0

I uploaded the document in SharePoint document library using CSOM. Now I need to Rename the uploaded file using CSOM, here is my code

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);
Naveen
  • 6,786
  • 10
  • 37
  • 85
  • What's the question? – André Schild Jul 08 '15 at 07:35
  • I don't think SharePoint provides an API to rename files in document library. However you can trick SharePoint by moving the file to the same document library and renaming it (including the file extension). I wrote an [**answer on SharePoint StackExchange**](http://sharepoint.stackexchange.com/a/140238/20540) which does this. However the code snippet is in JavaScript so you would have to modify it for CSOM. – Naveen Jul 08 '15 at 08:18

0 Answers0