C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » ASP.NET/Web Applications »

Using CAML(Collaborative Application Markup Language) in sharepoint


Posted Date: 19 Oct 2008    Resource Type: Articles    Category: ASP.NET/Web Applications
Author: Srinivas Member Level: Gold    
Rating: 1 out of 5Points: 10



We can use CAML to Retrieve the data from the list of sharepoint.
Caml is a Xml Format and it requires FieldRef attibutes which specifies the sharepoint specific columns in list

To query a list using the CAML we need the sharepoint specific column names in that required.So first we need to retrieve them.we can do that with follwoing code


SPSite site = new SPSite("siteUrl");
SPWeb web = site.OpenWeb();
SPList employeeList=web.Lists["listName"];
SPQuery query = new SPQuery(employeeList.Views[viewName]);
System.Diagnostics.Debug.WriteLine(query.ViewXml);
Response.Write(query.ViewXml);


This gives the sharepoint specific column names of the list.Let us suppose you got the "employeename" column as "title" and salary as "pay".

The following CAML retrieves the employees whose salary is greater than say 50000


CAML query
"<Query><Where><Gt><FieldRef Name="pay"/><Value Type="int">50000</Value>
<Gt></Where></Query> "


then execute the query with following code


SPSite site = new SPSite(siteName);
SPWeb web = site.OpenWeb();
SPList employeesList = web.Lists[listName];
SPQuery query = new SPQuery(employeesList.Views[viewName]);
query.Query = "<Query><Where><Gt><FieldRef Name="pay" /><Value Type="int">50000</Value>
</Gt>
</Where>
</Query>";
SPListItemCollection filteredEmployees = employeesList.GetItems(query);
foreach (SPListItem i in filteredEmployees)
{
Response.Write(i["title"].ToString() + " " +
i["pay"].ToString());
}


Here FieldRef specifies the share point specific column and Value Type refers the data type of the column



Responses

Author: Puja Sharma    21 Oct 2008Member Level: Gold   Points : 1
Good Article.
One query.
I tried using caml query to search for a field for a value like Q&B.

The query is notworking when the search value contains &.

Any wayout?


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Sharepoint  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Default Text Field Values That Disappear on Focus.
Previous Resource: Cookie
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET/Web Applications


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use