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?
精彩评论