我在visual studio 2013中创建了可视化Web部件。我想阅读
我正在阅读第一个列表字段标题正确的休息是随机数,我不知道我在哪里做错了
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
}
但我正在从网络部分
获取以下输出
答案 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>";
}