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

23,977

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

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

        }
    }
}
Share:
23,977
Rushikesh
Author by

Rushikesh

Updated on July 05, 2022

Comments

  • Rushikesh
    Rushikesh almost 2 years

    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>");
    
                }
            }
        }
    
  • Rushikesh
    Rushikesh about 11 years
    Thanks a lot for help..It is working but I can mark only one answer