SharePoint: Using MoveTo method with special characters in CSOM returns error

sahar fiuzati hagh 1 Reputation point
2022-03-24T13:46:11.507+00:00

Hi,

when I'm trying to move a file to a subsite which has special characters (for example emoji) in the name, CSOM returns this error : The file or folder name "something" contains invalid characters. Please use a different name. Common invalid characters include following: # % * : < > ? / |

Does anyone have any idea how to solve it?

BR,

Microsoft 365 and Office SharePoint Development
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2022-03-25T02:39:23.187+00:00

    Hi @sahar fiuzati hagh ,
    I feel regretful to inform you that it turns out to be a by-design one.
    This means in the file name, it has some invalid characters which SharePoint files not supported, you could check the official document for more detailed information:
    Invalid file names and file types in OneDrive, OneDrive for Business, and SharePoint
    186716-image.png
    We are also unable to get create a folder which name contains " * : < > ? / \ |
    186756-image.png
    The only way to solve it is to replace " * : < > ? / \ | to valid characters.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



  2. Rob Windsor 2,001 Reputation points
    2022-03-28T13:54:43.14+00:00

    This isn't really a full answer, but I hope it will help. It looks like Microsoft added a new type, Microsoft.SharePoint.Client.ResourcePath to the Client Object Model to help with special characters in file and folder names. I'm not sure if this also applies to special characters in site URLs.

    Supporting % and # in files and folders with the ResourcePath API

    It looks like they also added a method to move a file that takes a ResourcePath as a parameter.

    File.MoveToUsingPath(ResourcePath, MoveOperations) Method

    I did a quick search but was unable to find any additional information on the use of Microsoft.SharePoint.Client.ResourcePath or File.MoveToUsingPath.

    Again, I hope this helps you solve your issue.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.