Вопрос

Hi i`m making a Windows application that analyse the SharePoint Site.

In SPWeb level, I want to get the value of list count. I tried to like this

SPWeb.Lists.Count.ToString();

But when I compare with that value, it`s different, not matched...

So I want to try make code, unfortunately, I`m just beginner of SharePoint...

Please somebody help me. give some examples or links about that.

Это было полезно?

Решение

This is because of the SPWeb.Lists.Count.ToString(); return the number of all lists and libraries not only lists

To can get the accurate number of lists only you should exclude the library and other list types from your code as the following

int listcount=0;

foreach (SPList list in Web.Lists)
        {
            if (!list.Hidden & list.BaseType != SPBaseType.DocumentLibrary &
                (
                    (int)list.BaseTemplate != 109 |     // Picture Library
                    (int)list.BaseTemplate != 851       // Asset Library
                ))
            {
listcount++;
            }
        }

If you need to get only the count of custom lists, try the following :

int listcount=0;

foreach (SPList list in Web.Lists)
        {
            if ((int)list.BaseTemplate == 100 )
            {
       listcount++;
            }
        }

To check all BaseTemplateID check Get the RegistrationId template list for a SharePoint custom action via Power Shell.

Другие советы

SPWeb.Lists.Count.ToString(); is correct way to find number of Lists for any SPWeb. You might be seeing in difference in count you see here and in Site is because SharePoint has couple of hidden list like UserInformation list, managed metadata list which are hidden from UI. Also we can hide our custom list by using powershell/server side code.

To give an idea and to identify total number of Hidden list, you can iterate through above Lists and match it with what your list on sites.

Try following code

 using (SPSite site = new SPSite("Web Url"))
  {
      using (SPWeb web = site.OpenWeb())
      {
          Console.Write(web.Lists.Count);
          Console.ReadLine();
      }
  }
Лицензировано под: CC-BY-SA с атрибуция
Не связан с sharepoint.stackexchange
scroll top