Hello and thanks for looking!
Background
I currently have a C# method for looping through a SharePoint List Collection and returning a lists of those SP Lists, including a nested list of their columns/SPFields.
Problem
How do I get a list of ONLY user-created fields in a SharePoint 2007 List via C#?
Code so far. . .
SPSite site = SPContext.Current.Site;
SPWeb web = site.OpenWeb();
web.AllowUnsafeUpdates = true;
SPListCollection lists = web.Lists;
var PellaListCollection = new List<PellaListModel>();
foreach (SPList l in lists) {
var PellaList = new PellaListModel();
var PellaListColumns = new List<PellaListColumn>();
foreach (SPField c in l.Fields) {
if (c.Hidden.Equals(false))
{
var type = c.FieldTypeDefinition.TypeName.ToString();
var col = new PellaListColumn
{
ColumnId = c.Id,
ColumnDataType = type,
ColumnTitle = c.Title
};
PellaListColumns.Add(col);
}
}
PellaList.ListColumns = PellaListColumns;
PellaList.ListId = l.ID;
PellaList.ListTitle = l.Title;
PellaList.Description = l.Description;
PellaListCollection.Add(PellaList);
}
web.AllowUnsafeUpdates = false;
return PellaListCollection;
}
As you can see, right now I am filtering by which SPFields are not "Hidden", but this still returns quite a few of the standard SharePoint generated fields with the list. I just need the fields the users have created.
Thanks!
Matt