Question

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

Was it helpful?

Solution

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

OTHER TIPS

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!

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();
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++;
        }
    }
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top