When iterating the fields of a list how do you know which columns are yours and which are built-in ?
I know a solution for "classic" SDK using SPField.SourceId (https://sharepoint.stackexchange.com/questions/95488/retrieving-columns-created-by-user-not-built-in-columns) but I can't find one for CSOM. I thought UserCreated was the way to go for but it looks like it's not
So how do you tell apart theirs and mine ? Using a combination of Hidden CanBeDeleted FromBaseType ? Checking for a list of special internalNames ?
ClientContext context = new ClientContext(siteUrl);
context.Credentials = creds;
Web web = context.Web;
var list = web.Lists.GetByTitle(listName);
context.Load(list.Fields);
context.ExecuteQuery();
foreach (Field field in list.Fields)
{
bool thisColumnWasCreatedByUser =
field .FromBaseType == false &&
//this.InternalName != "Title" && // builtin but I'd rather keep it
field .InternalName != "_dlc_DocId" && // probably safe
field .InternalName != "_dlc_DocIdUrl" &&
field .InternalName != "_dlc_DocIdPersistId" &&
field .InternalName != "Combine" && // sucks
field .InternalName != "RepairDocument" // sucks too
}
EDIT
Mixing suggestions by Viraj Gorajia and Dikesh Gandhi, my current solution is
bool thisColumnWasCreatedByUser =
field .FromBaseType == false &&
(!field .SchemaXml.Contains(" SourceID=\"http")) && // remove "Title", "Combine", "RepairDocument"
(!field .EntityPropertyName.StartsWith("OData__")) // field .Sealed == true could be working too but I don't know if it could exclude valid results