We sometimes need to add lists,document/image libraries to a site automatically, or in other words when a feature is activated.To do that,we need a Feature Receiver class and on Feature Activated,we need to write the code for asdding list/doc library/picture library

using (SPSite siteCollection = new SPSite(“Absolute_url”))
{
using (SPWeb mySite = siteCollection.OpenWeb())
{
SPListCollection _Lists = mySite.Lists;
try
{
if (_Lists[strListName] != null)
Message += ” List Already Exists”;

}
catch(Exception ex)
{
Guid listGuid = _Lists.Add(“MapPicLibrary”, “Map Picture Library”, SPListTemplateType.PictureLibrary);
}
}
}

Advertisements