Collaborative Application Markup Language (CAML )
Collaborative Application Markup Language (CAML) is the XML-based language that is used to build and customize Web sites based on SharePoint Team Services. CAML can be used to provide schema definition to the Web site about how the site looks and acts, define views and forms for data and page rendering or execution, act as a rendering language that performs functions in the DLL like pulling a value from a particular field and others.
The focus is to pull required information from a SharePoint site. The code is as under:
SPSite sp = new SPSite(“site URL”);
SPWeb Website = sp.OpenWeb();
SPList DocLib = Website.Lists[“Doc Library Name”];
Suppose that we want to get the list of all the documents based on criteria that the value of Column “IsData” is 0. Then, the query will be like
SPQuery SelectQuery = new SPQuery(DefaultView); //creating a query for the default view
SelectQuery.Query = “<Where><Eq><FieldRef Name=’IsData’/><Value Type=’Text’>0</Value></Eq></Where>”; //select query
SPListItemCollection SelectedDoc = DocLib.GetItems(SelectQuery); // getting list of files returned by select query
int a = SelectedDoc.Count; // gives the number of documents selected
You can use string.Format to write the query.
You can get all the fields of the rows by using
DataTable as under: DataTable table = docLib.GetItems(SelectQuery).GetDataTable();
One or more field types are not installed properly. Go to the list settings page to delete these fields.
One reason can be column name column don’t match the internal column name. Like the column name ‘SO#’ may change by SharePoint to an other name like ‘SO_XXX’.
One simple way is to find the internal name of the column by opening the source of the web page where one enters the value of the document before uploading it to the document library.
Other is to use U2U CAML Query Builder and use it to graphically write the CAML query.