MOSS Publishing Pages and Encoded GUID’s

Home » SharePoint Development » MOSS Publishing Pages and Encoded GUID’s

MOSS Publishing Pages and Encoded GUID’s

Posted on

While working on a web part for a client’s MOSS public web site I discovered some strange behavior regarding GUID’s embedded in query string arguments.  My web part, a simple viewer that replaces the functionality of the old ‘txtlstvw’ page from SharePoint 2003, takes the GUID of a list and an item ID as query string arguments, instantiates new SPSite and SPWeb objecs, fetches the list by GUID, retrieves the item by ID, and renders several fields in a formatted display.  The web part is deployed in a web part zone on a custom layout page in MOSS.  Like I said, simple.
 
But there’s a hitch – passing a GUID in the query string argument to to the page caused it to throw a ‘value cannot be null’, parameter name ‘virtualPath’ error.  No matter what format the GUID was in, with curly braces, without curly braces, encoded to replace the braces and dashes, nothing worked.  In troubleshooting this problem I discovered by accident that removing only one character from the GUID caused the page to load without error.  Very strange.
 
Somehow it seems that the safe mode parser is inspecting the URL when the page loads and throwing an exception if it encounters a GUID.  Now, I know what you’re going to say – SharePoint passes GUID’s all the time in query strings, especially in the list configuration pages.  This is true but it’s also worth mentioning that all such pages are in the ‘/_layouts’ directory and not in the root virtual directory context of the web application.
 
In any event, I simply wrapped the GUID inside of normal brackets [ ] then parsed the brackets out of the string in my web part code.  I can’t really explain why this ‘feature’ exists or what it’s purpose might be but if you stumble over it like I did now you know how to get around it.
 
Happy SharePointing!