开发者

Sharepoint 2010 SPListTemplate how to get list of fields?

开发者 https://www.devze.com 2023-02-13 02:28 出处:网络
I need to get all fields from my list template? How can i do this? var web = site.OpenWeb(); var template = web.ListTemplates[\"SomeTemplate\"];

I need to get all fields from my list template? How can i do this?

var web = site.OpenWeb();
var template = web.ListTemplates["SomeTemplate"];
template ... ???? -There is no method to get fi开发者_JAVA技巧elds.


There is no built-in method to get all fields from a list template. The only way you can get the fields is by parsing the Schema XML of the list and getting all <Field> and <FieldRef> tags.

Easier is to create a list instance, which you can query later on with the following examples.

To get all fields from a list you can use the SPList.Fields Property, e.g. like so:

foreach (SPField spField in myList.Fields)
{
    //your code here
}

MSDN SPListItem.Fields

You can also get all fields from a list item "in reverse" SPListItem.Fields Property. You might also be interested in this SO thread: Check if a List Column Exists using SharePoint Client Object Model?

0

精彩评论

暂无评论...
验证码 换一张
取 消