I am working on an app that when a file is created through Office, it asks the user to input the values for the fields that are stored in the Library's List. While that works great, I am completely unable to update that created file without updating its list item information and, while I have tried a huge range of options, it always override everything. I cannot ask the user to re-enter those values and the file might be in-memory or downloaded from SharePoint Online directly.
I only want to update the file's content, and I can use a byte[]
or a Stream
as needed. I am using this right now, just to try stuff out:
using (var context = new ClientContext(repositoryUri + "subSiteName"))
{
context.Credentials = CurrentUser.Credentials;
var web = context.Web;
try
{
context.Load(web.Lists, all => all.Where(l => l.RootFolder.Name == "libraryName").Include(l => l.RootFolder));
context.ExecuteQuery();
var list = web.Lists.FirstOrDefault();
var folder = list.RootFolder;
context.Load(folder, f => f.Files);
context.ExecuteQuery();
var file = folder.Files.Where(f => f.Name == "fileName" /* hard-coded for testing */).FirstOrDefault();
var fileInformation = new FileCreationInformation
{
Content = fileData,
Url = file.ServerRelativeUrl,
Overwrite = true // false: throws, true: overwrites list item
};
var newFile = folder.Files.Add(fileInformation);
context.ExecuteQuery();
}
catch (Exception ex) // just to read exception messages
{
}
}
Is there a way to just update the binary? I use the REST API but now switched to CSOM to see if there was any better option.