Home > Microsoft SharePoint, Microsoft SharePoint 2010, MOSS2007 > Get all picture libraries in a web

Get all picture libraries in a web

Hi Friends,

While working in MOSS2007 or in SharePoint 2010 we may come across a situation where we need to get all the picture libraries, all task lists or all KPI list and so on.

This is required in many scenarios like in tool part we want a picture library to be displayed in drop down to be given for selection of one picture library.

In following code I am showing two ways using which you can get all picture libraries from a web.

 using (SPSite site = new SPSite(""))
  using (SPWeb web = site.OpenWeb())
     //we will get all lists in this web
     SPListCollection listCollection = web.Lists;

     // first way is to use the GUID for TemplateFeatureId of picture library
     foreach (SPList eachList in listCollection)
         if (eachList.TemplateFeatureId == new Guid
             ddl.Items.Add(eachList.Title);//here you will get picture libraries

     //second solution will be using the template name
     SPListTemplate Templatetype = SPContext.Current.Web.
                                        ListTemplates["Picture Library"];
     foreach (SPList list in listCollection)
         if (list.BaseTemplate == Templatetype.Type)
             ddl.Items.Add(list.Title);//here you will get picture libraries

Similarly you can use this post http://blogs.technet.com/b/vinitt/archive/2009/11/04/list-of-feature-id-listtemplate.aspx to get the other TemplateFeatureId’s and template name. Using this you can similarly get other types lists also.

  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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: