Search This Blog

Monday, January 3, 2011

To Display All List Of Items

Open C# Windows Form , write the below code in the button click event.
private void btnSPList_Click(object sender, EventArgs e)
string strSiteAddress = "http://server"; // E.g: "http://pravahaminfo-pc:1234";  
           //SPSite is returning the site collection.
                SPSite rootSite = new SPSite(strSiteAddress);
           //SPWeb is returning top level site
                SPWeb rootWeb = rootSite.OpenWeb();
           // Represents a collection of SPList objects
                SPListCollection listCollection = rootWeb.Lists;
 //Note : Two ways we can display, you can show list by using for loop or foreach 
          for (int i = 0; i < listCollection.Count; i++)
MessageBox.Show("List Follows : " + listCollection[i].ToString());
         // OR
          foreach (SPList list in listCollection)
                    MessageBox.Show("List follows : " + list.ToString());

No comments:

Post a Comment