SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What is the best way to remove illegal characters from sharepoint(MOSS) filenames, foldernames, urls, etc...

Basic character removal process is not enough...

Thanks in advance SAV

share|improve this question
up vote 2 down vote accepted

You can use the SPEncode class to do what you want.

Your choices are :


Good luck !

See :

share|improve this answer
That doesn`t remove common illegal characters which SharePoint cant eat example [ ~ # % & * { } \ : < > ? / + | " . _ ] – SAV Oct 27 '10 at 19:20
RegularExpression is useful for that but...I think there is no built in method for that in SP API – SAV Oct 27 '10 at 19:23… – SAV Oct 27 '10 at 19:25
Found answer and method snippet exampl about the whole thing...… Great example and blog post about it – SAV Oct 27 '10 at 19:32
It is useful for files and folders. Bu you should keep the Encode methode for the URL ! Thanks for the links, they are interesting ! – Sébastien Levert Oct 27 '10 at 19:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.