Sunday, October 9, 2011

Retrieving the SharePoint List

There are two types of data retrieving in the SharePoint one method is using the SharePoint Web Service and other method is Using SharePoint dll. Today I am doing the second method, To use this method you need to do development in the SharePoint server or else that you can develop your own machine and deploy it in the machine and check but you are not able to debug it.

But this method is easy than the web service data retiring method following code is illustrate how to retrieve data form SharePoint list

SPSite site = new SPSite(SPContext.Current.Web.Url);

SPWeb web = site.OpenWeb();

string ID = "7E49165B-9216-4c86-85F8-44732646EF06"

SPList Events = web.Lists["Events"];
SPQuery query = new SPQuery();
query.Query = " " + 
           ID + " ";
SPListItemCollection EventItems = Events.GetItems(query);
SPListItem CurrentItem = EventItems[0]; 
// assigning retirveing value
DateTime EventDateValue = (DateTime)CurrentItem["Event Date and Time"];
Label lblTitle = new Label();
lblTitle.Text = CurrentItem["Event Title"].ToString();
lbldate.Text = EventDateValue.ToString("dd MMMM yyyy, hh.mm tt");
lblDes.Text = CurrentItem["Event  Mini Description"].ToString();
   
PnlTitle.Controls.Add(lblTitle);
                   

0 comments:

Post a Comment