You are hereCode Snippet

Code Snippet


Add choices to Sharepoint Multi-Choice Field

Setting field values of a list item in SharePoint is easy.  But when it comes to Multi-Choice fields, the code is a big different.  The following code shows how values can be added to a multi-choice field.

SPFieldMultiChoice choiceField = (SPFieldMultiChoice)myWeb.Fields["choiceFieldName"];
choiceField.Choices.Add("Value");
//Set PushChangesToLists to true if automatic update of List or Content types is required
choiceField.PushChangesToLists = false; 
choiceField.Upate();

Use CAML Query to Read Data from lists or Libraries

One way to read the data from a list or a library is to iterate through it using the items collection of the list or library. But this is not the most efficient way to do it, specially if only few items are needed from this list.

Enter CAML Queries.

The following is the example query

<Where>
  <Eq>
    <FieldRef Name="Title" />
      <Value Type="Text">title</Value>
  </Eq>
</Where>

One thing to note in the CAML Query is that there is <query> start and end tag.  It is required that the query string does not have starting and ending <query> tag, otherwise the SPQuery will always return a empty dataset.

And here is the code:

SPList mylist = web.Lists["MyList"];
SPQuery spQuery = new SPQuery();
spQuery.Query = "" //CAML Query String;
SPListItemCollection queryitems = mylist.GetItems(spQuery);

That is it, as simple as that.

There as a great tool to build CAML Queries at http://www.u2u.info/SharePoint/U2U%20Community%20Tools/Forms/AllItems.aspx called U2U Caml Query Builder.  It is worth checking this tool out.