如何以编程方式从sharepoint站点获取所有文档库的列表

时间:2013-03-05 09:18:54

标签: sharepoint sharepoint-2010 sharepoint-2007 splist

我正在使用下面的代码,它给了我列表&文件库;但我想获取只有文档库的列表。 请帮助我如何区分列表和&文档库以编程方式

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>");

            }
        }
    }

2 个答案:

答案 0 :(得分:8)

请参阅this Post

尝试这种方式:

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>");
      }
  }
}

希望它的帮助!!

答案 1 :(得分:3)

尝试这样的事情

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>");

        }
    }
}