Showing posts with label SharePoint My Practices. Show all posts
Showing posts with label SharePoint My Practices. Show all posts

Sunday, March 28, 2010

SharePoint My Practices

Q) 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://jaganinfo-pc:17303";

//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());