7

I`m making SharePoint site Analysis program.

And I have a question.

In Sites(SPWeb) Level, I want to count document library.

So I`m using SPWeb.DocTemplate Property like this.

public class WebInfos
{
    public void GetWebInfos(SPWeb web, ref ListInfos listinfos)
    {             
         listinfos.SiteDocumentLibCount = web.DocTemplates.Count.ToString();
    }
}

But the all sites result is always same...

Am I using wrong property? or make a method??

Please somebody help me

4 Answers 4

10

No need for looping , just get the library at a specific site based on the base type equal to DocumentLibrary then get count of collection as the following :

using(SPSite site = new SPSite("https://yoursiteURL"))
{
  using (SPWeb web = site.OpenWeb())
  {   

    SPListCollection libcol = Web.GetListsOfType(SPBaseType.DocumentLibrary);
    libcol.Count;
  }
}
1
  • 1
    Thank you M.Qassas. As you mentioned, no need for looping. And it works well!!! :)
    – Ryden Choi
    Commented Dec 1, 2016 at 7:08
6

You can try this- as bellow

using(SPSite oSite = new SPSite("https://server/site"))
{
  using (SPWeb oWeb = oSite.OpenWeb())
  {
      SPListCollection docLibraryColl = oWeb.GetListsOfType(SPBaseType.DocumentLibrary);

      docLibraryColl.Count;
  }
}

Click Here & Here for reference.

Hope this will help you!

0
2

Get the document library count using LINQ:

    SPSite site = new SPSite("siteURL");
    SPWeb web = site.OpenWeb();

    var totalDocLibrary = (from SPList lst in web.Lists
                          where (lst.BaseType.Equals(SPBaseType.DocumentLibrary) && !lst.Hidden) 
                          select lst).Count();
1
using(SPSite site = new SPSite("https://sitecollectionurl"))
{
  using (SPWeb web = site.OpenWeb())
  {
    int i = 0;
    foreach (SPList list in web.Lists)
    {
        if (list.BaseType == SPBaseType.DocumentLibrary)
        {
            i++;
        }
    }
  }
}
1
  • 1
    Thank you Gautam Sheth. But Ram`s answer is same as my situation.
    – Ryden Choi
    Commented Dec 1, 2016 at 7:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.