简体   繁体   English

如何使用C#以编程方式从SharePoint网站获取所有图片库的列表

[英]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.

相关问题 如何使用c#获取Sharepoint List - How to get Sharepoint List using c# 如何使用 c# 以编程方式将文档从 Sharepoint 2010 迁移到 sharepoint online - How to migrate documents from Sharepoint 2010 to sharepoint online programatically using c# 如何使用ac#client从SharePoint 2010站点注销? - How to logoff from a SharePoint 2010 site using a c# client? 如何在C#,Sharepoint 2010中以编程方式删除列表的视图? - How to delete a list's view programatically in C#, Sharepoint 2010? 如何在C#中使用sharepoint客户端模型获取所有内容类型组的列表 - how to get a list of all content type groups using sharepoint client model in c# 如何使用 powershell/c# 列出 SharePoint 中的所有 2013 工作流 - How to list all 2013 workflows in SharePoint using powershell/c# 如何使用C#以编程方式创建共享点导航栏 - How to create sharepoint navigation bar programatically using c# 如何在C#中以编程方式从共享点服务器检出文件? - How to checkout a file from a sharepoint server programatically in C#? 使用C#以编程方式远程上传Sharepoint - Remote Upload Sharepoint programatically using C# 如何使用C#以编程方式从SP Farm获取所有SharePoint Web应用程序? - How to get all SharePoint Web Applications from SP Farm programmatically using C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM