使用CSOM创建包含特殊字符的新文件 [英] Creating new file with special characters using CSOM

查看:60
本文介绍了使用CSOM创建包含特殊字符的新文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您是


我正在使用CSOM创建新文件。文件名包含特殊字符。



文件名为!@@#$#%$%^^& ^&(())(_ + {}}。rar和如果我创建文件名,它会失败或部分创建



FileCreationInformation f_ObjInfo   =  new FileCreationInformation();
$
f_ObjInfo.ContentStream = new MemoryStream();

f_ObjInfo.Url            = f_Url +" /" + System.Web.HttpUtility.UrlEncode("!@@#$#%$%^^& ^&(())(_ + {}}。rar") ;


f_DestFolder.Files.Add(f_ObjInfo);

f_DestFolder.Update();

f_CContext.ExecuteQuery();



如何处理创建文件的特殊字符?



解决方案

嗨Ruyam,


我测试了下面的代码片段使用无效字符错误抛出异常:

 using(ClientContext ctx = new ClientContext(" http:// sp / sites / dev /"))
{
List documentsList = ctx.Web.Lists.GetByTitle(" doc2");
ctx.Load(documentsList);
ctx.ExecuteQuery();
var fileCreationInformation = new FileCreationInformation();
byte [] bytefile = System.IO.File.ReadAllBytes(@" C:\!@@#


#%


< blockquote>%^^& ^&(())(_ + {}}。rar");
fileCreationInformation.Content = bytefile;
fileCreationInformation.Overwrite = true;

fileCreationInformation.Url =" http:// sp / sites / dev / doc2 /!@@#


Hi

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

The file name is !@@#$#%$%^^&^&(())(_+{}}.rar and 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+ "/"+System.Web.HttpUtility.UrlEncode("!@@#$#%$%^^&^&(())(_+{}}.rar");
f_DestFolder.Files.Add(f_ObjInfo);
f_DestFolder.Update();
f_CContext.ExecuteQuery();

How can I handle special characters wile file creation?

解决方案

Hi Ruyam,

I tested the code snippet below and it throws the exception with invalid character error:

 using (ClientContext ctx= new ClientContext("http://sp/sites/dev/"))
            {
                List documentsList = ctx.Web.Lists.GetByTitle("doc2");
                ctx.Load(documentsList);
                ctx.ExecuteQuery();
                var fileCreationInformation = new FileCreationInformation();
                byte[] bytefile = System.IO.File.ReadAllBytes(@"C:\!@@#


#%


%^^&^&(())(_+{}}.rar"); fileCreationInformation.Content = bytefile; fileCreationInformation.Overwrite = true; fileCreationInformation.Url = "http://sp/sites/dev/doc2/!@@#


这篇关于使用CSOM创建包含特殊字符的新文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆