Find out structure of View using CAML query

To find out the structure of the view that you want to query, you can actually query a view instead of the list itself. So, after getting a reference to an SPList, you can create a SPQuery object for a specific view in the list.

SPSite site = new SPSite(“http://mysharepointsite”);
SPWeb web = site.OpenWeb();
SPList trainersList = web.Lists[“DemoList”];

SPQuery query = new SPQuery(testList.Views[“All Items”]);

The SPQuery object has a property ViewXml returning the necessary information to create your CAML string.


<View System.Xml.XmlAttributeCollection><Query></Query><ViewFields><FieldRef Name=”LinkTitleNoMenu” /><FieldRef Name=”Email” /><FieldRef Name=”Topics” /></ViewFields><RowLimit>100</RowLimit></View>

We can use this information to construct the following CAML string:

string strCaml = “<Where><Eq><FieldRef Name=’LinkTitleNoMenu’/>” +  “<Value Type=’Text’>Hello World</Value></Eq></Where>”;


~ by Neha Sinha on February 22, 2008.

One Response to “Find out structure of View using CAML query”

  1. Thank you!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: