Solved

Filter custom list from all sharepoint lists

Posted on 2011-03-22
4
584 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 31

Expert Comment

by:Jamie McAllister MVP
ID: 35187845
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
ID: 35188263
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
ID: 35188332
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
ID: 35229667
Gr8 Solution
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The vision: A MegaMenu for a SharePoint portal home page The mission: Make it easy to maintain. Allow rich content and sub headers as well as standard links. Factor in frequent changes without involving developers or a lengthy Dev/Test/Prod rel…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

733 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