Step 3.import the name space "Microsoft.SharePoint" by
using Microsoft.SharePoint;
Step 4.Write the following code in the Main() block
string sitePath = "http://manab:36069/sites/DevSite/";
// enter object model through site collection.
SPSite siteCollection = new SPSite(sitePath);
// obtain reference to top-level site.
SPWeb site = siteCollection.RootWeb;
// enumerate through lists of site
foreach (SPList list in site.Lists)
{
Console.WriteLine(list.Title);
}
Console.ReadLine();
// clean up by calling Dispose.
site.Dispose();
siteCollection.Dispose();
Step 5.Run your console application clicking on F5,You will get following output as follows
The complete code is as follows.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
namespace SPListGet
{
class Program
{
static void Main(string[] args)
{
string sitePath = "http://manab:36069/sites/DevSite/";
// enter object model through site collection.
SPSite siteCollection = new SPSite(sitePath);
// obtain reference to top-level site.
SPWeb site = siteCollection.RootWeb;
// enumerate through lists of site
foreach (SPList list in site.Lists)
{
//if you want to populate only the document library,otherwise
//remove the if condition
if(list.BaseTemplate==SPListTemplateType.DocumentLibrary)
{
Console.WriteLine(list.Title);
}
}
Console.ReadLine();
// clean up by calling Dispose.
site.Dispose();
siteCollection.Dispose();
}
}
}
No comments:
Post a Comment