Tuesday, June 9, 2009

Advanced List View Filtering

The filter section of views is limited at best, and in some cases it is just wrong. For example if you have a list and you want to filter based on this boolean expression:
Expression 1: ((Column1=A OR Column2=B) AND Column3=C) OR Column4=D
you would think you could expand the expression (because list view filters don't have parentheses) to
Expression 2: Column4=D OR Column3=C AND Column1=A OR Column3=C AND Column2=B
The SharePoint UI will group the expression in a different way, not based on the order of operations (often giving you empty results, and always giving you the wrong results)
However, SharePoint designer allows you to modify the filter yourself (of course it's kind of a pain).
  1. First make sure you've attempted to put your filter expression into view through the UI (this will place the appropriate columns in your Where clause so it will be easier to move things around.
  2. Open the list view page in SharePoint designer
  3. Find the <listviewxml> node
  4. Between the node you'll see that there is a lot of cryptic looking text that has a lot of &lt; and &gt; markup in it. This is the XML markup for the list view definition, we'll need to modify a part of this to alter the list view correctly
  5. Within this cryptic text look for '<Where', this is the beginning tag of the where clause. Once you find it, place your cursor before the '&' and highlight to the '\Where>'
  6. Copy this entire expression and paste it into notepad (or any other text editor)
  7. Do a replace on the text, replacing '&lt;' with '<' and '&gt;' with '>', now the text looks like xml (optionally, put in line breaks to make it easier to read)
  8. Now you have to build your expression, my suggestion is to start with the outermost expression and work your way in
    For example, Expression 1 builds up like so (this example doesn't include the correct syntax for the columns, only the logic):











  9. When you finally have it correct, remove your line breaks, and do a replace swapping '<' for '&lt;' and '>' for '&gt;'
  10. Paste the new where clause over the old where clause and save the page (this will customize the page from the site defintion)
  11. Test

Tuesday, June 2, 2009

SharePoint gets a minus

A while back I created several page layouts for my company so that we would have a standard format for pages, news stories, etc. We really hadn't had any problems until one of our news stories had a '+' in it's title, and thus the suggested filename had a '+' in it. Apparently you are allowed to create a page with the special character '+' in it, but it will break your page.

The behavior we saw was that you could see all the page content in edit mode, but none of it would show up when it was checked in/published. Also, there was some odd rendering of the page in edit mode.

I was scratching my head over this for a while and pretty much randomly stumbled onto the solution. In the future, I'd suggest removing any non alpha-numeric characters from file names just to be safe, even though SharePoint doesn't warn you or remove them.