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

Free Support Forum - aspose.com

Maintain Password Protection Status

Hi
I am using Aspose Word to add Custom Properties to a document before I open it. Currently I do the following

_document = new Aspose.Words.Document((documentPath));

Where documentPath is a string to the location of my document.,
Once I have the document I can updated the Custom Properties.

What I have found is that this call invokes a (IncorrectPasswordException) so the properties do not get added,

When the document is launched Word prompts me for the password,

Now I did try the following.
loadOps.Password = promptValue;
_document = new Aspose.Words.Document((documentPath),loadOps)

This works and unprotects the document . However it seems to totally unprotect it. So Word launches without prompting for a password and if I check the Word Properties it is no longer protected. So if I save the document it saves unprotected.

My questions is how can I emulate Word behavior . If you Open a password protected document you do not need to enter the password again when you close the document.

How can I unprotect the document to add the custom properties whilst still maintaining the “protected” status of the document so that when it is closed it saves protected

Thanks
Nick

So I wondered if I needed to save again using the following to make this password protected.
DocSaveOptions options = new DocSaveOptions();

            options.Password = "Test";
            options.SaveFormat = SaveFormat.Docx;

         
            testdoc.Save(textBoxDocPath.Text, options);

However I do not seem to be able to select DOCX as a save format. I get an error .
: ‘An invalid SaveFormat for this options type was chosen.’

If I do not specify a saveformat it seems to use DOC and then I get an error when I try to open the document.

I am way of course here?

@LNGLEEVFDEV

To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a standalone console application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Please note that Aspose.Words mimics the behavior of MS Word. If you open the protected document in MS Word, unprotect it for editing and save it. MS Word does not save it with restrict editing. You need to protect it again.

The DocSaveOptions class is used for DOC file format and OoxmlSaveOptions class is used for DOCX file format. So, please use OoxmlSaveOptions in your code.

Thanks
I also realized I need to use WRITEPROTECTION method instead
LoadOptions loadOps = new LoadOptions();
string promptValue = “password”;
loadOps.Password = promptValue;

        Document testdoc = new Document("..\\..\\Docs\\password.docx", loadOps);

        testdoc.WriteProtection.SetPassword("password");
        testdoc.WriteProtection.ReadOnlyRecommended = false;

        testdoc.Save("C:\\TEMP\\TEST5.DOCX");

You can close this call now

@LNGLEEVFDEV

It is nice to hear from you that your problem has been solved. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.