Saturday, January 23, 2010

Validate url to be used for a SharePoint site (replace illegal characters)

I made a function to check if a string contains illegal characters to be used as an URL for a new SharePoint site. This is useful to use when calling the Webs.Add function to programmatically create a new site in SharePoint where a user has provided the desired site url.

I took a look at the Create Site page in SharePoint. SharePoint calls a JavaScript function "IndexOfIllegalCharInUrlLeafName", which can be found in the "commonvalidation.js" on your SharePoint server. After the function call, SharePoint will check for a '+' character separately.

This is the function i've created. Illegal characters are replaced with a '-' character.

(you can download the code in a text file here)

1 comment:

public key infrastructure said...

Grateful to check out your website, I seem to be ahead to more excellent sites and I wish that you wrote more informative post for us. Well done work.