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

Rushikesh picture Rushikesh · Mar 5, 2013 · Viewed 24k times · Source

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

            }
        }
    }

Answer

Jignesh Rajput picture Jignesh Rajput · Mar 5, 2013

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!!