SharePoint Designer \ Data Form Web Part apostrophe bug
Posted
Friday, July 25, 2008 12:48 PM
by
Itay Shakury
Problem:
You try to use a Data Form Web Part (Data View Web Part) to display a document library in an XSLT view. You find out that documents that include an apostrophe character (') in their file name, cannot be opened or viewed. (There might be other problematic characters beside apostrophe, I haven't checked that)
Steps to reproduce:
- Create a document library. Add some files with apostrophe in their name to the library.
- Click on one of those items. The file opens as expected.
- Open SharePoint Designer 2007, and browse to the document library. Open the page you have just viewed (Forms\Allitems.aspx).
- In design mode, right click on the document library web part (List View Web Part) and click on "Convert to XSLT view".
- Save the page, and open it in browser.
- Click on one of the items again. This time the file won't open, giving you 400 error.
Cause:
This bug is happening because the URL of the file is now encoded, converting apostrophe chars to this: '. This encoding format is good for HTML and not for URL.
To prove this, try to replace the ' part of the URL with the original apostrophe char.
See how the document is opening without any problems?
Solution:
Modify the XSLT that SharePoint Designer generates, and use the {@ServerUrl} instead of the {@FileRef} attribute.
- Open SharePoint Designer 2007 and navigate to the page containing the Data Form Web Part. (follow the "Steps to Reproduce" above)
- In Code view,search for the following peace of code:
HREF="{@FileRef}" - Replace it with the following peace of code:
HREF="{@ServerUrl}" - Save the page.
* ServerUrl does not encode apostrophe at all.If you want, you can still encode apostrophe chars (in the URL format encoding) - Use {@EncodedAbsUrl}, or manually encode the string using XSLT or Javascript.
That's it, now browse again to that page you have just modified, and see for yourself - Opening a file with apostrophe in it's name actually works.