tags:

views:

49

answers:

1

I have a drive on my computer that has folder--some of which have lots of folders w/in other folders and also contain files.
I need to migrate these docs into sharepoint, however a LOT of these folders and files have invalid characters that will not allow me to migrate into sharepoint (i.e. " / \ &, etc.)

Is there any way to write something in C# that basically removes these invalid characters from all folders and files?

Please help!

+1  A: 

Yes. A way to do this would be to drill through the directory structure recursively, and for each file name, check if it is valid, and if it is not valid, make a valid filename, and upload to Sharepoint.

You can make a Regex that matches all disallowed characters, and replace them with an allowed character, such as underscore. If you need names to be unique, and you are worried you might create duplicate names with this approach, store all names that has been used (ie. uploaded to Sharepoint) in something like a HashSet, and check that before using the generated name. If the name already exists, you can add a pre- or suffix, flag for human intervention, or do something else, depending on your requirements.

driis
Microsoft.SharePoint.Utilities.SPUrlUtility.IndexOfIllegalCharInUrlLeafName(string strLeafName) will help to detect invalid chars.
Jason