Skip to content

SPSite.OpenWeb error: ‘url’ contains illegal character

August 22, 2012

The SPSite.OpenWeb(webUrl) method does not like when it is called with an url parameter that is url encoded.

Imagine that a user created a new site which is called “My new site”. The url that you see in the browser when you open this site will be something like http://server/sites/My%20new%20site
If you pass this url to the OpenWeb, then it will throw an exception, saying that the url contains illegal characters (%).

Note, that for example Uri.AbsolutePath returns urlencoded path which can contain illegal characters. So you should not pass it directly to OpenWeb but make sure that the “%20” and other encoded parts are converted back to the original characters.

Advertisements

From → SharePoint

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: