阅读SharePoint列表字段标题

时间:2014-12-17 16:37:29

标签: asp.net sharepoint-2013 web-parts

我在visual studio 2013中创建了可视化Web部件。我想阅读

  1. 列出字段标题
  2. 列表数据
  3. 我正在阅读第一个列表字段标题正确的休息是随机数,我不知道我在哪里做错了

    我的清单

    enter image description here

    我的C#类

    protected void Page_Load(object sender, EventArgs e)
        {         
            using (SPSite _site = new SPSite(SPContext.Current.Web.Site.Url))
            {
              using (SPWeb _web = _site.OpenWeb())
              {
                  SPList _list = _web.Lists["MyUWLContent_List"];
    
                  SPView _view = _list.DefaultView;
    
                  //Get a collection of view field names. 
                  StringCollection _viewFields = _view.ViewFields.ToStringCollection();
    
                  // Print the value of each view field. 
                  foreach (string fieldName in _viewFields)
                  {
                      Label1.Text += fieldName + "<BR>";         
                  }
              } //end SPWeb
            } //end SPSite 
    }
    

    但我正在从网络部分

    获取以下输出

    enter image description here

1 个答案:

答案 0 :(得分:0)

不确定为什么要拨打ToStringCollection(),但你可以这样做:

// Get your list
SPList myList = web.Lists["MyUWLContent_List"];

// Get the default view
SPView defaultView = someList.DefaultView;

// Loop through all the fields in the default view
foreach (SPField field in defaultView.ViewFields)
{
    // this gets the title of your field
    var fieldTitle = field.Title;

    Label1.Text += fieldTitle + "<BR>"; 
}