Specific Word files cannot be copied over to a Sharepoint shared drive.

100questions
100questions used Ask the Experts™
on
When trying to copy specific Word Document files to a SharePoint drive hosted with Microsoft, the message comes up which says:  Can't Read from the Source or File Disk.
Yet, if this file is copied to another network drive, for a server on site, it copies over without producing this message.
If the file is renamed without the # sign in the name of the file, then the file can be copied over to the SharePoint drive.
Any suggestions as to why this is happening?  So far they have all been Word documents with the # sign contained in the name.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

Commented:
# is an illegal character in sharepoint, there are more here is a powershell script to check files
   

function Check-IllegalCharacters ($Path, [switch]$Fix, [switch]$Verbose)
    {
        <#
            .SYNOPSIS
            Describe purpose of "Check-IllegalCharacters" in 1-2 sentences.

            .DESCRIPTION
            Add a more complete description of what the function does.

            .PARAMETER Path
            Describe parameter -Path.

            .PARAMETER Fix
            Describe parameter -Fix.

            .PARAMETER Verbose
            Describe parameter -Verbose.

            .EXAMPLE
            Check-IllegalCharacters -Path Value -Fix -Verbose
            Describe what this call does

            .NOTES
            Place additional notes here.

            .LINK
            URLs to related sites
            The first link is opened by Get-Help -Online Check-IllegalCharacters

            .INPUTS
            List of input types that are accepted by this function.

            .OUTPUTS
            List of output types produced by this function.
        #>


        Write-Verbose -Message Checking
        #Get all files and folders under the path specified
        $items = Get-ChildItem -Path $Path -Recurse |Select-Object Fullname
        foreach ($item in $items)
        {
            #Check if the item is a file or a folder
            if ($item.PSIsContainer) { $type = "Folder" }
            else { $type = "File" }
           
            #Report item has been found if verbose mode is selected
            if ($Verbose) { Write-Verbose -Message Found }
           
            #Check if item name is 128 characters or more in length
            if ($item.Name.Length -gt 127)
            {
                Write-Verbose -Message $type
            }
            else
            {
                #Got this from http://powershell.com/cs/blogs/tips/archive/2011/05/20/finding-multiple-regex-matches.aspx
                $illegalChars = '[&{}~#%]'
                filter Matches($illegalChars)
                {
                    $item.Name | Select-String -AllMatches $illegalChars |
                    Select-Object -ExpandProperty Matches
                    Select-Object -ExpandProperty Values
                }
               
                #Replace illegal characters with legal characters where found
                $newFileName = $item.Name
                Matches $illegalChars | ForEach-Object {
                    Write-Verbose -Message $type
                    #These characters may be used on the file system but not SharePoint
                    if ($_.Value -match "&") { $newFileName = ($newFileName -replace "&", "and") }
                    if ($_.Value -match "{") { $newFileName = ($newFileName -replace "{", "(") }
                    if ($_.Value -match "}") { $newFileName = ($newFileName -replace "}", ")") }
                    if ($_.Value -match "~") { $newFileName = ($newFileName -replace "~", "-") }
                    if ($_.Value -match "#") { $newFileName = ($newFileName -replace "#", "") }
                    if ($_.Value -match "%") { $newFileName = ($newFileName -replace "%", "") }
                }
               
                #Check for start, end and double periods
                if ($newFileName.StartsWith(".")) { Write-Verbose -Message $type }
                while ($newFileName.StartsWith(".")) { $newFileName = $newFileName.TrimStart(".") }
                if ($newFileName.EndsWith(".")) { Write-Verbose -Message $type }
                while ($newFileName.EndsWith("."))   { $newFileName = $newFileName.TrimEnd(".") }
                if ($newFileName.Contains("..")) { Write-Verbose -Message $type }
                while ($newFileName.Contains(".."))  { $newFileName = $newFileName.Replace("..", ".") }
               
                #Fix file and folder names if found and the Fix switch is specified
                if (($newFileName -ne $item.Name) -and ($Fix))
                {
                    Rename-Item $item.FullName -NewName ($newFileName)
                    Write-Verbose -Message $type
                }
            }
        }
    }

Open in new window

Author

Commented:
Thanks very much David.
I will try this out..

Author

Commented:
David, I can't seem to get the script to work though... Is there a way I can specify the path for it to look into including subfolders?
Top Expert 2016
Commented:
from within powershell run the script. one run the function will be in memory then
to just check
Check-IllegalCharacters -Path c:\yourpath -verbose
to check and fix
Check-IllegalCharacters -Path c:\yourpath -verbose -fix

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial