Friday, April 13, 2012

Error when trying to create new Uri using value from SPListItem[“FileRef”]

I have taken over maintenance of a SharePoint solution recently deployed to SharePoint 2010 (which was previously running on SharePoint 2007).
It has a timer job that runs checks unprocessed items in a library, if it has more than 5 attachments, it proceeds to great a compressed file for these items. Within this procedure it uses the SPListItem[“FileRef”] to create a new Uri. When it does this I get the following error:

Message: Error attaching files: , Invalid URI: The format of the URI could not be determined. at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind) at …

According to the uses this was working before in SharePoint 2007. The reason it fails is because the SPListItem[“FileRef”] returns a relative url.
I have amended this to use the Encoded Abs Url, so that my code now looks like this:

lst.FileURL = item["ows_EncodedAbsUrl"].ToString();

This works.

No comments:

Post a Comment