[英]How to get list of all picture libraries from SharePoint site programatically using C#
I'm building a web part for SharePoint 2010 to get all the document libraries and picture libraries in two dropdown list. 我正在为SharePoint 2010构建一个Web部件,以在两个下拉列表中获取所有文档库和图片库。 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());
}
}
}`
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)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.