Free Support Forum - aspose.com

Protect word document from openning without a password

Hi, guys!

I want to know - does Aspose supports encryption of document. I dont' need to protect my document from updating data. I need to protect it from openning without a password. Earlier I found that it was not supported in previous versions. Maybe it supports this feature now? And how, if it does?

Thanks,

Yulia.

Hi Yulia,


Thanks for your inquiry. Please note that Aspose.Words supports most document protection features. Using Aspose.Words you can open a document that is password protected even without the password (as long as its not encrypted). Once document is loaded into Aspose.Words DOM, you can remove any protection from a document. You can use Document.Unprotect method to removes protection from the document regardless of the password. This method unprotects the document even if it has a protection password.

See the following links in the documentation for further information:
http://www.aspose.com/docs/display/wordsnet/Protecting+Documents
http://www.aspose.com/docs/display/wordsnet/DocSaveOptions+Class
http://www.aspose.com/docs/display/wordsnet/OoxmlSaveOptions+Class

Hi!

I want to create document that can be opened (viewed) only with password prompt. No need to protect data from updating - I need to protect from VIEWING. Another words, I want to create document and encrypt it with password.

Hi Yulia,


Thanks for your inquiry.
Yulkand:
I want to create document that can be opened (viewed) only with password prompt.
You can use DocSaveOptions.Password property sets a password to encrypt document using RC4 encryption method as shown in following code snippet.

Document doc = new Document();<o:p></o:p>

DocSaveOptions options = new DocSaveOptions(SaveFormat.Doc);<o:p></o:p>

options.Password = “test”;

doc.Save(MyDir + “AsposeOut.doc”, options);


Please read following documentation links for your kind reference.

http://www.aspose.com/docs/display/wordsnet/DocSaveOptions+Class
http://www.aspose.com/docs/display/wordsnet/OoxmlSaveOptions+Class


Yulkand:
No need to protect data from updating - I need to protect from VIEWING. Another words, I want to create document and encrypt it with password.

Please use the Document.Protect to protects the document with specific protection type as shown in following code snippet.


<span lang=“EN-GB” style=“font-size:10.0pt;font-family:“Courier New”;color:#2B91AF;mso-font-kerning:
0pt;mso-no-proof:yes”>Document<span lang=“EN-GB” style=“font-size:10.0pt;
font-family:“Courier New”;mso-font-kerning:0pt;mso-no-proof:yes”> doc = new Document();<o:p></o:p>

doc.Protect(ProtectionType.ReadOnly, "password");
doc.Save(MyDir + "AsposeOut.doc");


Moreover, following code example p
rotects a section so only editing in form fields is possible.


// Create a blank document

Document doc = new Document();

// Insert two sections with some text

DocumentBuilder builder = new DocumentBuilder(doc);

builder.Writeln("Section 1. Unprotected.");

builder.InsertBreak(BreakType.SectionBreakContinuous);

builder.Writeln("Section 2. Protected.");

// Section protection only works when document protection is turned and only editing in form fields is allowed.

doc.Protect(ProtectionType.AllowOnlyFormFields);

// By default, all sections are protected, but we can selectively turn protection off.

doc.Sections[0].ProtectedForForms = false;

builder.Document.Save(MyDir + "Section.Protect Out.doc");


Hope this answers your query. Please let us know if you have any more queries.