Reputation: 55
I'm building a web part for SharePoint 2010 to get all the document libraries and picture libraries in two dropdown list. I am able to get all document libraries using the below code. How do I get all picture libraries in a site.
`string currentSite = SPContext.Current.Web.Site.Url;
List<string> libraryList = new List<string>();
using (SPSite oSite = new SPSite(currentSite))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
SPListCollection docLibraries = Web.GetListsOfType(SPBaseType.DocumentLibrary);
foreach (SPList list in docLibraries)
{
libraryList.Add(list.Title.ToString());
}
}
}`
Upvotes: 0
Views: 925
Reputation: 550
well, you could try checking the list base template:
var pictureLibs = new List<string>();
foreach(var list in oWeb.Lists){
if(list.BaseTemplate.Equals(SPListTemplateType.PictureLibrary))
pictureLibs.Add(list.Title);
}
this should get you only those libraries which are based on the standard picture lib template.
however, if you want to get any kind of list which contains pictures you could go for checking the content types of each list, the condition for this would look something like:
if(list.ContentTypes.Any(x => x.Id.IsChildOf(SPBuiltInContentTypeId.Picture)))
Upvotes: 1