Home > SharePoint 2010 > Programmatically Get List of Document Libraries in SharePoint 2010

Programmatically Get List of Document Libraries in SharePoint 2010


Hi all,

try this example to get a list of all Document Libraries in SharePoint 2010 Programmatically

1) Open VS2010 and create a new Empty Sharepoint Project

2) Right click on the project and Select Add New item then select Visual User Control and give it any name

3) From Toolbox drag DropdownList into Visual User Control and set ID=”ddl_List”

4) In Code behind add the following code


using (SPSite site = new SPContext.Current.Site)
 {
 using (SPWeb web = site.OpenWeb())
 {
 SPListCollection ListColl = web.Lists;
 foreach (SPList _lst in ListColl)
 {
 if (_lst.BaseTemplate == SPListTemplateType.DocumentLibrary)
 {
ddl_List.Items.Add(_lst.Title);
 }
 }
 }
 }

5) Build and Deploy the project

Hope this helps

Good Luck

Hope this helps

Advertisements
Categories: SharePoint 2010
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: