You can use the below code to update file content of existing file with new content and file name.
static void ReplaceFileContentWithNewFile(ClientContext context, string sourceLibraryName, int itemId, string newFilePath, string newFileName) {
List sourceLibrary = context.Web.Lists.GetByTitle(sourceLibraryName); ListItem item = sourceLibrary.GetItemById(itemId); Microsoft.SharePoint.Client.File file = item.File; context.Load(item, i => i.File); context.ExecuteQuery(); using (FileStream fs = new FileStream(newFilePath, FileMode.Open, FileAccess.Read)) { var fileCreationInfo = new FileCreationInformation { ContentStream = fs, Url = file.ServerRelativeUrl, Overwrite = true }; Microsoft.SharePoint.Client.File uploadFile = context.Web.RootFolder.Files.Add(fileCreationInfo); context.Load(item); context.ExecuteQuery(); } string newFileUrl = file.ServerRelativeUrl.Replace(file.Name, newFileName); file.MoveTo(newFileUrl, MoveOperations.Overwrite); context.ExecuteQuery();
}