CharlZ's Blog

Ramblings about SharePoint, etc.

Fun with CAML Joins

I was working with joins using a CAML query for the first time today and I was using this document to learn about this topic:

While I was working on building my query, I kept receiving the error "Value does not fall within the expected range."  This was happening each time I tried to set value of the SPQuery.Join property.  I was following the format of the example in the article for this property.  It begins with "<Joins>", contains multiple "<Join>" nodes, and ends with "</Joins>".  It turns out that adding the "<Joins>" outer node caused the error.  I simply needed to add each of the "<Join>" nodes without wrapping them inside a "<Joins>" node.  After I had it sorted out, it made some sense to me, but it is pretty frustrating when the MSDN documentation is misleading.

This also applies to the ProjectedFields and ViewFields properties as well.

The one limitation that is problematic to me is that choice fields cannot be used as projected fields.  This forced me to redesign my choice fields as lookup fields.

Bug in WSS 3.0 Picture Library after upgrade to SharePoint 2010


After upgrading content from WSS 3.0 to SharePoint Foundation 2010, we discovered the following behavior when clicking on an image inside of a picture library:
This behavior was only observed on picture libraries that existed prior to the upgrade. Any picture libraries that we created after the upgrade process did not suffer from this issue.  When I opened the AllItems.aspx pages in for each list in SharePoint Designer 2010, I could see that each page used different web parts to display the list of items. The upgraded content (originally in WSS 3.0) used a ListViewWebPart object to display the list of items and the newly created list used an XsltListViewWebPart.
Further investigation of the upgraded picture library revealed that the error message was being generated due to an invalid URL to list item page that was being constructed by SharePoint. SharePoint was generating a URL that looked like the following:
http://<Server>/<Site>/_Layouts/listform.aspx?PageType=4&ListId={GUID}?ID=XX&Source=<URL of original source page>&RootFolder=<Folder where image resides>
Because of the duplicated question marks in the query string portion of the URL, the page fails to load. When I manually modified the URL to contain an ampersand instead of a second question mark, the list item page was displayed.


The resolution to this issue turns out to be fairly simple, all though potentially time consuming if your affected site has many picture libraries. The steps are detailed below: 
  1. Open the AllItems.aspx page of the affected list
  2. In the top left hand corner of the page, click Site Actions / Edit Page
  3. Edit the properties of the list view web part and press OK on the tool part. This step appears to fix whatever values are corrupted in the list view web part’s properties.
  4. Reload the page and it should work correctly.
  5. Repeat this for each view in the list.
These steps appear to work for the All Items view, but may not correct any of the standard list views.

Further Analysis

After comparing the ListViewXml data from the page prior to the fix and page after the fix, we can see that SharePoint has modified some of the underlying JavaScript to correct the URL it constructs to the list item details page.

Original Page

fImglibDefautlView = true;

urlCmdForDisplay = ctx.displayFormUrl + "?RootFolder=]]>

Corrected Page

fImglibDefautlView = true;
strSeperator = "&";
if (ctx.displayFormUrl.indexOf("?") == -1)
            strSeperator = "?";
urlCmdForDisplay = ctx.displayFormUrl + strSeperator + "RootFolder=]]>

Programmatic Fix

I have put together a console application that will process all of the lists on your SharePoint farm and correct the invalid markup in the views.  Download the Visual Studio 2010 project below: (59.12 kb)