Create a site-column of type user, multichoice and multiuser using Sharepoint Client Object Model

1.3k Views Asked by At

I'm trying to create site-columns with following types: Text, Note, Number, Choice, User, MultiUser, MultiChoice

I've implemented it for all the types except for User, MultiChoice and MultiUser. Can't seem to find how to achieve it. This is what I've achieved so far.

StringBuilder choiceFieldGenericShema = new StringBuilder();
                choiceFieldGenericShema.Append("<Field Type='Choice' Format='Dropdown' Group='{1}' Name='{0}' DisplayName='{2}' Status='{3}' > <CHOICES> ");
                choiceFieldGenericShema.Append("</CHOICES>  </Field> ");
                string choicFieldSchema = string.Format(choiceFieldGenericShema.ToString(), columnItem.Title, columnItem.GroupName, columnItem.Name, columnItem.Status);
                var newField = web.Fields.AddFieldAsXml(choicFieldSchema, true, AddFieldOptions.DefaultValue);
                clientContext.Load(newField);
                clientContext.ExecuteQuery();

Can anyone please suggest a way following the above method to achieve my task? Thanks in advance!

2

There are 2 best solutions below

0
hbulens On

I suggest you take a look at these articles:

In this case, you'll need to tweak with some attributes to toggle multi select for a choice + user field:

Choice:

<Field Type="MultiChoice" 
DisplayName="Labels_Selected" 
FillInChoice="FALSE" 
Group="Sample Site Columns" 
ID="{2fdf0ba7-0052-4e9f-80f6-e7669ac4ae4f}"
SourceID="http://schemas.microsoft.com/sharepoint/v3"
StaticName="LabelsSelected" Name="LabelsSelected"> 
</Field>

User:

<Field ID="{A0372EB5-A947-41CA-A5FA-A34C29D2FB88}"
Name="Employee"
DisplayName="Employee"
Type="UserMulti"
Required="TRUE"
StaticName="Employee"
UserSelectionMode="PeopleOnly"
Group="SampleGroup"/>
0
Anil Gangwar On

You can create site column using csom, below is code

string schemaChoiceField = "<Field ID='<GUID>' Type='Choice' Name='SideDishesChoice' StaticName='SideDishesChoice' 
   DisplayName='Side dishes' Format='RadioButtons'>"
   + "<Default>Patatoes</Default>"
   +         "<CHOICES>"
   +         "    <CHOICE>Fresh vegetables</CHOICE>"
   +         "    <CHOICE>Beans</CHOICE>"
   +         "</CHOICES>"
   + "</Field>";

For dropdown or radio button follow the link http://projectservercode.com/create-choice-type-site-column-using-csom-sharepoint/