Sharepoint: Removing illegal characters from filenames prior to bulk uploading

By peter.stilgoe









If you are doing a migration from a filesystem to Sharepoint you will more than likely come across problems uploading documents to Sharepoint that contain illegal characters in their filenames.

In Sharepoint the following characters are classed as illegal characters – & ” : * ? <> # {} % ~ / \ Tab

The + character can also cause problems & should be avoided in filenames & sitenames.

Below are some useful Powershell scripts to help you remove the illegal characters prior to uploading your documents to Sharepoint.

List all files containing a specific character (in this case ‘&’)

gci -rec | ? {-not $_.psicontainer -and $_.name.Contains("&")}

Count the number of files containing a specific character (in this case ‘&’)

(gci -rec | ? {-not $_.psicontainer -and $_.name.Contains("&")}).Count

Replace a specific character with another, in our case the ‘&’ with the word ‘and’

gci -rec | ? {-not $_.psicontainer -and $_.name.Contains("&")} | % {rename-item $_.fullname -newname ($_ -replace "&","and")}

Share

, , , ,

About... peter.stilgoe

peter.stilgoeThis author published 497 posts in this site.
Sharepoint, InfoPath, K2, Nintex, Business Process Mapping, Business Intelligence, Automation, ECM, Document Management, Document Imaging, Internet Marketing & Online Business Consultant Email / MSN: pstilgoe@hotmail.com LinkedIn: Pete Stilgoe - Sharepoint Consultant









Share

FacebookTwitterEmailWindows LiveTechnoratiDeliciousDiggStumbleponMyspaceLikedin

6 Comments

  • At 2011.09.22 12:36, Jamil said:

    Hello Pete,

    Nice article. Very helpful.

    What are my immediate options (free tool) in order to bulk upload files with metadata? I have found followings but none satisfy the bulk-load requirements.

    For example:

    CodePlex: http://spbulkdocumentimport.codeplex.com Seems like meta-data not supported
    http://docuploadmetadata.codeplex.com – not sure if its still a good download b/c low traffic, no documentation, author deleted source code, no comments…

    Powershell: http://get-spscripts.com/2010/10/bulk-upload-files-with-metadata-into.html – Does not support Data/Time fields

    Free Tool: http://roxority.com/uploadzen-documentation/better-sharepoint-bulk-file-uploads-with-uploadzen.html – Looks like no meta-data support…

    [Reply]





    peter.stilgoe

    peter.stilgoe Reply:

    Have a look at Colligo Contributor

    [Reply]





    • At 2011.10.19 13:38, Kercheval said:

      Hi Peter

      I’m from South Africa and a client that I’ve been working with requires all their product documents uploaded into a SharePoint library. There are about 40 500 files with around 3000 files that have character’s in the names. I found that out using SharePrep , unfortunately it is not a free tool. After searching a bit more I found your site. Thanks so much, your code has saved me a huge amount of time and effort.

      But I have another major problem. I need to upload all these files and specify the required metadata. Would you know how I can bulk upload with metadata? Can this be done using powershell?

      Thanking you in advance for your help.

      [Reply]

      • At 2011.10.19 13:44, Pete said:
        peter.stilgoe

        Hi,

        Previously I have purchased a single copy of Colligo Contributor to do bulk uploads with metadata, I think they have a free trial you can test with prior to purchase….

        [Reply]

        • At 2011.10.20 08:20, Kercheval said:

          Hi

          Thanks so much for your quick response. But I don’t think my company would want to purchase a software that would be used just once, in fact they have asked me to do this manually. I have been looking for an easier solution using powershell.
          Do you think it would be possible for me to do a bulk upload with metadata using powershell or am I wasting my time and should just go about uploading them manually?

          Thanks again Peter for your time

          [Reply]

          • At 2012.02.01 18:21, Stephen Owen said:

            Hmm…I like this a lot but can’t seem to use this to remove plus signs in some file names. I keep getting invalid regular expression notices when I try.

            [Reply]

            (Required)
            (Required, will not be published)