Solved

Filter custom list from all sharepoint lists

Posted on 2011-03-22
4
548 Views
Last Modified: 2012-05-11
In my scenario I am trying to get all the lists and display in checkbox list control(please see screenshot)
foreach (SharePointclientObj.List list in site.Lists)
{
System.Web.UI.WebControls.ListItem item = new System.Web.UI.WebControls.ListItem(list.Title, list.DefaultViewUrl);

checkBoxListName.Items.Add(item);
}

 

As this is working fine but its showing all the lists which are inbuit in sharepoint. I wanted to fetch only the custom list which are created by users in the sharepoint site.
How do I filter custome list from all the lists?

Screenshot.png
0
Comment
Question by:prdeshpande
  • 2
  • 2
4 Comments
 
LVL 31

Expert Comment

by:Jamie McAllister MVP
Comment Utility
I've done this before and it wasn't easy. There's nothing in the object model to denote that it is a system list.

My solution was to gather the GUIDs of the out of the box lists (they are created by features and therefore are always the same), and I used that list of GUIDs to exclude those lists so that only my custom lists were shown.

I'm not aware of an easier solution than that.
0
 
LVL 1

Author Comment

by:prdeshpande
Comment Utility
Hey thx for reply,Can you please elaborate on your statements or I appreciate if you can share me some code snippets
0
 
LVL 31

Accepted Solution

by:
Jamie McAllister MVP earned 500 total points
Comment Utility
excludeListTemplates = new ArrayList();
          excludeListTemplates.Add("df31abb1-d432-4fa5-bdb1-25a2a5dd7e86");
          excludeListTemplates.Add("00bfea71-2062-426c-90bf-714c59600103");
          excludeListTemplates.Add("22a9ef51-737b-4ff2-9346-694633fe4416");
          excludeListTemplates.Add("00bfea71-a83e-497e-9ba0-7a5c597d0107");
          excludeListTemplates.Add("942d046c-fcf7-4901-ace0-7305b17c1c12");
          excludeListTemplates.Add("00bfea71-6a49-43fa-b535-d15c05500108");
          excludeListTemplates.Add("00bfea71-7e6d-4186-9ba8-c047ac750105");
          excludeListTemplates.Add("00bfea71-ec85-4903-972d-ebe475780106");
          excludeListTemplates.Add("00bfea71-a83e-497e-9ba0-7a5c597d0107");

          try
          {
              
              string output = string.Empty;

              foreach (SPList list in SPContext.Current.Site.RootWeb.Lists)
              {
                  if ((!list.Hidden) || (!chkFilterList.Checked))
                  {
                      //The following Template Feature Ids are excluded:
                      //Caml Query List:                df31abb1-d432-4fa5-bdb1-25a2a5dd7e86
                      //Links:                          00bfea71-2062-426c-90bf-714c59600103
                      //Pages:                          22a9ef51-737b-4ff2-9346-694633fe4416
                      //Tasks:                          00bfea71-a83e-497e-9ba0-7a5c597d0107
                      //Website Settings:               942d046c-fcf7-4901-ace0-7305b17c1c12
                      //Team Discussion:                00bfea71-6a49-43fa-b535-d15c05500108
                      //Contacts:                       00bfea71-7e6d-4186-9ba8-c047ac750105
                      //Events:                         00bfea71-ec85-4903-972d-ebe475780106
                      //Workflow Tasks:                 00bfea71-a83e-497e-9ba0-7a5c597d0107

                      if (!excludeListTemplates.Contains(list.TemplateFeatureId.ToString()) || (!chkFilterList.Checked))
                      {
                          drpLists.Items.Add(list.Title);
                      }

                  }
 
              }

              
          }
          catch (System.Exception)
          {
              //Handle It
          }

Open in new window

0
 
LVL 1

Author Closing Comment

by:prdeshpande
Comment Utility
Gr8 Solution
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Microsoft SharePoint Foundation 2010 and Microsoft SharePoint Server 2010 do not offer the option to configure the location of the SharePoint diagnostic trace log files during installation.  This can, however, be configured through Central Administr…
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now