Showing posts with label SharePoint Designer. Show all posts
Showing posts with label SharePoint Designer. Show all posts

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.

Filter by Person or Group Column Type

The Problem: I have a column called Attendees of the type "Person our Group." Furthermore, Attendees can contain multiple entries. When someone is viewing this view, I'd like them to be able to only see the items in which they are listed as an attendee.

When I try to filter by the criterion Attendees contains [Me] I get the following error:

"The filter type you selected cannot be used with this type of column. You can apply the 'contains' operator only to the columns that have the type Single line of text, Multiple lines of text, or Choice. Specify a different operator for the filter or change the column type. You can then attempt to create the filter again."

Lame!

To get around this, I use SharePoint Designer.

First, through the web interface I create the view that I want and filter on a random text column (e. g. randomTextColumnName contains [Me]). If I view the page now it'll say <!-- #RENDER FAILED -->. Whatever Microsoft.

To fix this, I now open the page for the view in the Designer and search for the internal name of my randomly chosen text column. When I get to the code that looks kind of like this:

...Contains&gt;&lt;FieldRef Name"TextColumnName"/&gt;&lt;...

(note that the quotation marks might read as &quot; - same difference for our purposes)
I can then change "TextColumnName" to the correct, internal name of the column (in my case, Attendees). Save and you're done.

Yeah. That's it. Silly, huh?