如何从SharePoint网站编程所有文档库的列表(How to get list of all d

2019-08-17 07:48发布

我使用下面的代码,给了我两个列表和文档库; 但我想只得到文档库的列表。 请帮助我如何区分编程列表和文档库

using(SPSite oSite = new SPSite("https://server/site"))
    {
        using (SPWeb oWeb = oSite.OpenWeb())
        {
            SPListCollection oLists = oWeb.Lists;

            foreach (SPList olist in oLists)
            {
                Response.Write(olist.Title+"<br>");

            }
        }
    }

Answer 1:

见这个帖子

试试这个方法:

using(SPSite oSite = new SPSite("https://server/site"))
{
  using (SPWeb oWeb = oSite.OpenWeb())
  {
      SPListCollection docLibraryColl = oWeb.GetListsOfType(SPBaseType.DocumentLibrary);

      foreach (SPList list in docLibraryColl)
      {
             Response.Write(list.Title+"<br>");
      }
  }
}

希望它可以帮助!



Answer 2:

尝试这样的事情

using(SPSite oSite = new SPSite("https://server/site"))
{
    using (SPWeb oWeb = oSite.OpenWeb())
    {
        SPListCollection oLists = oWeb.Lists;

        foreach (SPDocumentLibrary olist in oLists.OfType<SPDocumentLibrary>())
        {
            Response.Write(olist.Title+"<br>");

        }
    }
}


文章来源: How to get list of all document libraries from sharepoint site programatically