We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Modify or Overwrite Content of a Read-Only Word File using C# .NET | Bypass UnauthorizedAccessException

taking inputpath of file which is readonly enabled after doing all changes when saving in same file throwing error .
readonly is mandatory but when saving in aspose how to overwrit file.


Windows (or any other OS) will not allow you to write to a read-only file on disk. To keep your changes, you will need to save the document with a new name or in a different location. However, if you try to save to the same read-only file, Aspose.Words will throw the following exception:

System.UnauthorizedAccessException: Access to the path 'E:\...\input.docx' is denied

However, you may try the following workaround to overwrite the content of a read-only document:

string path = "E:\\Temp\\input.docx";
Document doc = new Document(path);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("new content");
// disable read-only attribue
File.SetAttributes(path, File.GetAttributes(path) & ~(FileAttributes.ReadOnly));
// Enable read-only attribue
File.SetAttributes(path, File.GetAttributes(path) | FileAttributes.ReadOnly);

thanks working fine.