October 26, 2009

Display data using SharePoint List GUID

If you have to show data from SharePoint List using CAML (Collaborative Application Markup Language) required looping thru each item in list. This method takes bit long time to execute when you have large data in list.


Here is the one of the simple method to retrieve data from a SharePoint List by user selected view that doesn’t require CAML.

I have given some abstracts here:

// My list name is VerbList
// GUID of the list is F9037F57-6DEB-4BA8-B1BA-85A0995DE882

SPList listName;
DataTable ListDataTable=new DataTable();
SPListItemCollection listItemColl=
listName.GetItems(qry, "{ F9037F57-6DEB-4BA8-B1BA-85A0995DE882}");
ListDataTable =listItemColl.GetDataTable();

In above syntax code lines

listName is object of SPList,where my data is stored.

qry is Query for which data to be displayed.

F9037F57-6DEB-4BA8-B1BA-85A0995DE882 is the GUID of the SPView from where I have to fetch data.

Make sure you use the GUID in Upper Case.

Retrived data will be stored in ListDataTable, you can use the data as you wish.

If you have any questions you can reach out our SharePoint Consulting team here.
By: Nehali

No comments:

Post a Comment