Friday, January 8, 2010

How to Hide List Views from the Drop Down List

If, like me, your SharePoint is closer to OOTB than not, when you create a new public list view the view automatically shows up in the drop down list in the upper right hand corner. This is neat if you want your users to be able to look at all of the views you create. Otherwise, not so much.

The Problem: I want people to be able to see the views I create but I don't want them to show up in the drop down list. I may or may not have accidentally created tons of views when I created new webpages in the Designer. Oops.

To remedy this I created a little command line program in C# that changes the Hidden property of the view. The MSDN documentation says that the SPView.Hidden property "specifies whether the view is hidden." Gee. Thanks. Helpful. Jerks. So, apparently this property lets you hide the view from the drop down list. I have no idea what else it does, though, so don't blame me if it blows your stuff up.

My code looks a little bit like this:

List<SPView> views = new List<SPView>();
foreach (SPView v in <my list>)
{
     if (<criteria goes here>)
     {
          views.Add(v);
     }
}
foreach (SPView v in views)
{
     v.Hidden = true;
     v.Update();
}

Yes, the two loops are necessary. Yes it's annoying. But yes, it works.

No comments:

Post a Comment