I'm trying to upload a file into a SharePoint document library using the C# CSOM library. The document library I'm uploading into has information rights management settings enforced.
When I try to upload a file (either a PDF document or a Word document - both without any sort of protection applied), I receive the following error message:
This library does not accept files of the given type. You must either upload a new, unprotected file that supports rights management or re-upload a document that was previously downloaded from this library
I was under the impression that both Word documents and PDF documents are supported by rights management? I've tried manually uploading both files through the SharePoint UI (to rule out a problem with the files I'm using) and they get added into the document library without any issues.
The code I'm using to upload the file is shown below (it's pretty much taken from the sample at https://github.com/OfficeDev/PnP/blob/master/Samples/Core.LargeFileUpload/Core.LargeFileUpload/FileUploadService.cs):
using (var ctx = GetContext(server))
{
Web web = ctx.Web;
ctx.Load(web.Lists, lists => lists.Include(list => list.Title, list => list.RootFolder));
ctx.ExecuteQuery();
if (!ListExists(ctx, web, listName))
{
throw new InvalidOperationException($"The list '{listName}' does not exist!");
}
FileCreationInformation newFile = new FileCreationInformation
{
ContentStream = fileStream,
Url = Path.GetFileName(fileName),
Overwrite = true
};
List docs = web.Lists.GetByTitle(listName);
Microsoft.SharePoint.Client.File uploadFile = docs.RootFolder.Files.Add(newFile);
if (fileProperties != null && fileProperties.Any())
{
var listItem = uploadFile.ListItemAllFields;
foreach (var fileProperty in fileProperties)
{
listItem[fileProperty.Key] = fileProperty.Value;
}
listItem.Update();
}
ctx.Load(uploadFile);
uploadFile.CheckIn("Initial checkin", CheckinType.MajorCheckIn);
ctx.ExecuteQuery();
}
Is there a step I'm missing?