Reputation: 1790
Is it possible to loop through field collection of a sharepoint list and retrieve only our custom fields and not the sharepoint built-in fields.
using (SPSite site = new SPSite("http://localhost/"))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["My List"];
foreach (SPField field in list.Fields)
{
//We also get sharepoint built-in column here. And we don't want that, just our
//custom created fields.
}
}
}
Any help would be appreciated.
Thanks
Upvotes: 4
Views: 5366
Reputation: 14880
You have two options:
SPBuiltInFieldId.Contains(field.Id)
Gets either the namespace that defines a built-in field or, if it a custom field, the GUID that identifies the list or Web site where it was created.
Upvotes: 9
Reputation: 1317
Here's a contrived (and currently untested) way:
string fieldTypeClass = field.FieldTypeDefinition.FieldTypeClass;
if (!(string.IsNullOrEmpty(fieldTypeClass) || fieldTypeClass.StartsWith("Microsoft.SharePoint"))) {
//Only custom fields here
}
Upvotes: 0
Reputation: 2480
I don't know if its really what you're looking for, of if LINQ is still "smiled upon" by .net digirati, but using LINQ to Sharepoint might work for you.
Upvotes: -2