Archive

Archive for February, 2012

Attaching event receivers to list

February 23, 2012 2 comments

Hi Friends,

SharePoint Event receivers are very impartment element in SharePoint infrastructure and as a developer we may need to create event receivers many times to meet the client requirement.

What if I need to create a List event receiver and to attach that to a list in my SharePoint site?

The easiest answer I can give at this point of time is to create a Feature receiver and in the feature activated event attach a receiver to a list using object model.

But there is yet another way which is quick than creating feature receiver. It is “SharePoint Event Receiver Manager (2007 & 2010)”.

This tool is a CodePlex project Contributed by .

I say this is a great tool to use in case of SharePoint Event Receivers development.

Note: complete contribution, development and license rights are with the team who have developed this and as per the Microsoft Reciprocal License . This post is just to make readers aware that this kind of tool exists.

Advertisements

Get all picture libraries in a web

February 14, 2012 Leave a comment

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
                                        ("00bfea71-52d4-45b3-b544-1c71b620109"))
         {
             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.