Sharepoint 使用CSOM重命名文档库中上载的文档
我使用CSOM在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 = "/" +
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修改它。