1

Am I missing something or is UserCreated boolean property really missing in Microsoft.SharePoint.Client.Field ?

When accessing _api/web/fields I can see data about AllowMultipleValues and UserCreated

<d:AllowMultipleValues m:type="Edm.Boolean">true</d:AllowMultipleValues>
<d:UserCreated m:type="Edm.Boolean">false</d:UserCreated> 

But I cannot find them on the object that is mapped to those data

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 f in list.Fields)
{
   no f.UserCreated
}

How can I retrieve those informations ?

EDIT My primary goal was to know if the column was created by the user rather than built in. UserCreated is not the way to know it. It's only available for taxonomy Field and I don't know what it is usefull for but it gives no indication about how the column was created.
I opened a new thread on this peculiar subject

2
  • What happens when you try to access that property?
    – wjervis
    Commented Nov 22, 2016 at 18:00
  • there's no such property for Field. As Kai noted it I can access theme by casting to a specialized type . This is an indication that this is not the property I was looking for. I was looking for a way to know if the column was created by the user rather than built in. This is not where you should look at it.
    – frenchone
    Commented Nov 23, 2016 at 11:16

2 Answers 2

1

Of course this can be done.

Like in server object model, client object model have a hierarchy of classes.
This particular properties not available on Field directly, but in order to get an access to those properties, you simply need to cast the field to an appropriate type.

Here is a very basic sample how you can do that:

var lookupField = ctx.Web.Fields.GetById(new Guid("dddd2420-b270-4735-93b5-92b713d0944d"));
var taxonomyField = ctx.Web.Fields.GetById(new Guid("e1a5b98c-dd71-426d-acb6-e478c7a5882f"));
ctx.Load(lookupField);
ctx.Load(taxonomyField);
ctx.ExecuteQuery();

if (lookupField.TypedObject is FieldLookup) // OR lookupField.TypeAsString == "Lookup", etc.
{
    var lookup = ctx.CastTo<FieldLookup>(lookupField);
    Console.WriteLine(lookup.AllowMultipleValues);
}

if (taxonomyField.TypedObject is TaxonomyField)
{
    var taxonomy = ctx.CastTo<TaxonomyField>(taxonomyField);
    Console.WriteLine(taxonomy.UserCreated);
} 

For reference microsoft.sharepoint.client.taxonomy.taxonomyfield (take a note on Inheritance hierarchy)

1
  • It looks like this is the right answer but this was not the right question. At the very start I wanted to know if a field was created by the user (rather than being a mandatory sharepoint "column" for a particular library type). From what I understand this is not what the UserCreated is for. Otherwise it will be on the base class. Thanks anyway
    – frenchone
    Commented Nov 23, 2016 at 8:32
-1

These 2 fields are missing in Managed client object model Field class. Please refer this link for available Properties in Microsoft.SharePoint.Client.Field Class.

You might have to rely on REST API to get this information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.