Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sharepoint 使用CSOM重命名文档库中上载的文档_Sharepoint_Csom - Fatal编程技术网

Sharepoint 使用CSOM重命名文档库中上载的文档

Sharepoint 使用CSOM重命名文档库中上载的文档,sharepoint,csom,Sharepoint,Csom,我使用CSOM在SharePoint文档库中上载了该文档。现在我需要使用CSOM重命名上传的文件,这是我的代码 Web web = context.Web; bool iscontinue = false; FileCreationInformation newFile = new FileCreationInformation(); newFile.Content = System.IO.File.ReadAllBytes(InputFileName); newFile.Url = "/" +

我使用CSOM在SharePoint文档库中上载了该文档。现在我需要使用CSOM重命名上传的文件,这是我的代码

Web web = context.Web;
bool iscontinue = false;
FileCreationInformation newFile = new FileCreationInformation();
newFile.Content = System.IO.File.ReadAllBytes(InputFileName);
newFile.Url = "/" + newFile;
List docs = web.Lists.GetByTitle(ConfigurationManager.AppSettings["DocumentLibraryName"]);
string strFilename = InputFileName;
//rename
List docs = web.Lists.GetByTitle("Shared Documents");
docs = web.Lists.GetByTitle(Convert.ToString(ConfigurationManager.AppSettings["DocumentLibraryName"]));

Microsoft.SharePoint.Client.File uploadFile = docs.RootFolder.Files.Add(newFile);
context.Load(uploadFile);
context.ExecuteQuery();

ListItem item = uploadFile.ListItemAllFields;

string renamefile = txtfilename.Text.ToString();

string docTitle = string.Empty;
item["Title"] = renamefile;

item.Update();

RenameFile(context, strFilename, renamefile);

问题是什么?我认为SharePoint没有提供API来重命名文档库中的文件。但是,您可以通过将文件移动到同一文档库并重命名它(包括文件扩展名)来欺骗SharePoint。我写了一篇文章来做这件事。但是,代码段是JavaScript的,因此您必须为CSOM修改它。