How to get list of all document libraries from sharepoint site programatically

对着背影说爱祢 提交于 2019-12-21 05:36:09

问题


I am using below code which gives me both list & document library; but I am trying to get list of only document libraries. Please help me how to differentiate list & document library programatically

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

            }
        }
    }

回答1:


See this Post

Try this ways :

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

Hope its helps!!




回答2:


Try something like this

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

        }
    }
}


来源:https://stackoverflow.com/questions/15219968/how-to-get-list-of-all-document-libraries-from-sharepoint-site-programatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!