MOSS Webpart-- MOSS列表的字段名称获取

代码
private void btn_ListSearch_Click(object sender, EventArgs e)
        {
            StringBuilder sb 
= new StringBuilder();
            SPSite site 
= null;
            
try
            {
                site 
= new SPSite(this.txtSiteUrl.Text);
                SPWeb spweb 
= site.OpenWeb(this.txtWebUrl.Text);
                
if (string.IsNullOrEmpty(this.txtListName.Text))
                {
                    
foreach (SPList list in spweb.Lists)
                    {
                        sb.AppendLine(
string.Format("列表名称:{0}:{1}", list.Title,list.Version));
                    }
                }
                
else
                {
                    SPList splist 
= spweb.Lists[this.txtListName.Text];

                    sb.AppendLine(
"【视图字段】");
                    
foreach (string fieldName in splist.DefaultView.ViewFields)
                    {
                        sb.AppendLine(
string.Format("字段名称:{0}", fieldName));
                    }
                    sb.AppendLine(
"\r\n【全部字段】");
                    
foreach (SPField field in splist.Fields)
                    {
                        sb.AppendLine(
string.Format("[{0}]:{1}", field.Title, field.InternalName));
                        
                    }                    
                }
                
                textBox4.Text 
= sb.ToString();
                MessageBox.Show(
"完成执行!");
            }
            
catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            
finally
            {
                
if (site != null)
                {
                    site.Dispose();
                }
            }
        } 

 

 结果显示

posted @ 2009-12-05 14:21  边缘凉风  阅读(271)  评论(0编辑  收藏  举报