0

I am using CSOM for creating new file. The file name contains specials characters.

The file name is !@@#$#%$%^^&^&(())(_+{}}.rar If I create file name as it is it gets fails or partially created

FileCreationInformation f_ObjInfo   =  new FileCreationInformation();
f_ObjInfo.ContentStream = new MemoryStream();
f_ObjInfo.Url           = f_Url+ "/"+"!@@#$#%$%^^&^&(())(_+{}}.rar"

f_DestFolder.Files.Add(f_ObjInfo);
f_DestFolder.Update();
f_CContext.ExecuteQuery();

How can I handle special characters wile file creation?

Update

I also tried with

 System.Web.HttpUtility.UrlEncode("!@@#$#%$%^^&^&(())(_+{}}.rar"); 

but not able to encode all characters properly.

Thanks in advance.

3
  • 1
    You could try doing a search on our beloved SP SE: link
    – Tally
    Commented Jun 28, 2018 at 14:24
  • Wha did UrlEncode return?
    – helb
    Commented Jun 28, 2018 at 14:26
  • It return !%40%40%23%24%23%25%24%25%5e%5e%26%5e%26(())(_%2b%7b%7d%7d.rar and after file creation it displays name as !@@#$%23%25$%25^^&^&(())(_+{}} which is not same as source
    – Mayuresh
    Commented Jun 28, 2018 at 14:32

1 Answer 1

0

To support # and % you should use new ResourcePath API

fileResourcePath = ResourcePath.FromDecodedUrl(f_Url+ "/"+"!@@#$#%$%^^&^&(())(_+{}}.rar");
f_DestFolder.Files.AddUsingPath(fileResourcePath, new FileCollectionAddParameters(), new MemoryStream());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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