3

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

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

            }
        }
    }
4

2 回答 2

8

看到这个帖子

试试这种方法:

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

希望它有帮助!

于 2013-03-05T09:40:27.647 回答
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>");

        }
    }
}
于 2013-03-05T09:30:24.320 回答