6

I'm building a webpart for SharePoint 2010 to get all the document libraries with usefull info for the user. This means, docs that users uploaded, etc. I don't want to show libraries such as Form Templates, Style Library, Customized Reports, etc...

I just want to show only the document libraries with usefull info, as Shared Documents, or any other users create in the future, is that possible?

Currently, my logic looks like this:

SPListCollection docLibraryColl = wb.GetListsOfType(SPBaseType.DocumentLibrary);

Guid docLibFeatId = new Guid("00bfea71-e717-4e80-aa17-d0c71b360101");

foreach (SPList list in docLibraryColl)
{
    if (list.TemplateFeatureId == docLibFeatId && !list.Hidden)
    {
        SPDocumentLibrary doclib = (SPDocumentLibrary)list;
        //rest of the logic here...  
    }
}

I've read here that Guid 00bfea71-e717-4e80-aa17-d0c71b360101 will return only libraries with MS Document Library template, but I'm still getting those undesired libraries in the results.

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
Brian Roisentul
  • 4,590
  • 8
  • 53
  • 81

2 Answers2

4

What's wrong with excluding the libraries you don't want in your if?

...
if (!list.Hidden && list.title != "Style Library" && list.title != "Form Templates")
...

You are already selecting the BaseType DocumentLibrary, so you will only receive document libraries, unfortunately form templates is a doclib too, so you will always get it in your selection.

Dennis G
  • 21,405
  • 19
  • 96
  • 133
  • Well I just was trying to avoid that, but well, I think I have no choice. – Brian Roisentul Feb 04 '11 at 15:29
  • I don't know of any other way to "exclude all MS stuff and only include my stuff"... in the end a forms library really IS just a regular document library... ;-) – Dennis G Feb 04 '11 at 22:58
1

I used this piece of code:

 if (docLib.Hidden || !docLib.AllowDeletion || docLib.IsCatalog || docLib.IsSiteAssetsLibrary || docLib.BaseTemplate == SPListTemplateType.WebPageLibrary)
{
   continue;
}
yianna
  • 11
  • 2