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

Free Support Forum - aspose.com

Remove write protection in Word 2010 document (docx)

Hi,

I have a password protected docx file. I need to remove the write protection using aspose and save the docx without protection. When i use the below code the docx protection is removed but when opening it shows some error message as “Word found unreadable content…” (Please see the error screen shots)

I am using Aspose.Words version 13.3.0.0.

Attachments
Input File is “PwdDocx.docx”. Its password is "test"
Output File is "TestOutput.docx"
Error screenshots are “err1.png” and “err2.png”.

This is my sample code:

using (System.IO.Stream stream = new System.IO.MemoryStream(input))
{
//TEST
Aspose.Words.Document wDoc = new Aspose.Words.Document(stream, new Aspose.Words.LoadOptions() { Password = “test” });
Aspose.Words.SaveFormat save = Aspose.Words.FileFormatUtil.LoadFormatToSaveFormat(wDoc.OriginalLoadFormat);
Aspose.Words.Saving.OoxmlSaveOptions sOptions = new Aspose.Words.Saving.OoxmlSaveOptions(save);
sOptions.Compliance = Aspose.Words.Saving.OoxmlCompliance.Iso29500_2008_Transitional;
System.IO.MemoryStream outStream;
//convert page by page
for (int i = 0; i < wDoc.PageCount; i++)
{
outStream = new MemoryStream();
options.PageIndex = i;
options.PageCount = 1;
//TEST
wDoc.Save(outStream, sOptions);
output = ConvertBinaryFileToArray(outStream);
ConvertedTiff.Add(output);
// Close/Dispose stream
outStream.Close();
}
}

//Convert stream to byte array
private byte[] ConvertBinaryFileToArray(MemoryStream inputStream)
{
BinaryWriter bwriter = new BinaryWriter(inputStream);
bwriter.Write(true);
byte[] array = inputStream.ToArray();
bwriter.Close();
inputStream.Close();
return array;
}

Hoping to get a solution as soon as possible.

Thanks
Jeshwel J

Hi Jeshwel,


Thanks for your inquiry. First off, I would suggest you please upgrade to the latest version of Aspose.Words (i.e. 13.6.0) from the following link:
http://www.aspose.com/community/files/51/.net-components/aspose.words-for-.net/default.aspx

Secondly, your document has no protection but it is encrypted that is why Microsoft Word asks for a password prior opening it. If you open/save this document by using the following code, the output document will not be encrypted, i.e. Microsoft Word will not ask you to enter the password to open it.

Document doc = new
Document(@“C:\Temp\PwdDocx.docx”,
new Aspose.Words.LoadOptions(LoadFormat.Docx, “test”,
“”));

doc.Save(@"C:\Temp\out.docx");


I hope, this helps.

Best regards,

Thanks Hafeez, I got know what i was doing wrong…everything works fine now.