How to lock the word content in C # And how to crack the locked content

Source: Internet
Author: User

How to operate a Word document in C #ArticleI also came to join in the fun box, but I don't want to write too much. Otherwise, I will look at the official website. After reading this article, I will find that nothing is the same!

There are always some Word documents, such as official documents and signed documents. After writing the documents, the Creator always locks the documents. Note: The lock I mentioned here is not the type of lock used to enter the password when opening the document, but allows you to open it normally, but cannot modify the text content or delete the text content, you cannot adjust the document format, or even copy and paste the content, and save the file as another one is still the kind of lock (you can't do anything bad if you want to do something ).

Next I will teach you how to implement this function in C # And learn this trick. Maybe you can show it one day. The implementation is very easy:

Public   Void Lockwordcontent ( String Filename, String Protectpwd)
{
Microsoft. Office. InterOP. Word. Application AP =   New Application ();
AP. Visible =   False ;
Object Objfilename = Filename;
Object OBJ = Type. missing;
// Open Word Document
Microsoft. Office. InterOP. Word. Document Doc = AP. Documents. Open ( Ref Objfilename,
Ref OBJ,
Ref OBJ,
Ref OBJ,
Ref OBJ,
Ref OBJ,
Ref OBJ,
Ref OBJ,
Ref OBJ,
Ref OBJ,
Ref OBJ,
Ref OBJ,
Ref OBJ,
Ref OBJ,
Ref OBJ,
Ref OBJ );

// The following operations are performed on the content in the document.
// ......

// The operation is complete. Before saving, the document is locked.
Object objprotectpwd = Protectpwd; // Locked Password
Object noset =   Null ;
Doc. protect2002 (wdprotectiontype. wdallowonlyformfields, Ref Noset, Ref Objprotectpwd );

Doc. Save ();

// Close the doc object later.
// ......
}

Looking at your success in locking the Word documents, you may have a bad smile, (* ^__ ^ ......
Slow down! The following method can crack all your locks, whether it isCodeThe lock is implemented in the word itself. You can only view, cannot modify, and cannot delete? In this way:
1. Close the locked document A. Doc.
2. Create a Word document B. Doc
3. In document B. Doc, open the menu "insert -- Object -- text in the file" in sequence (I am office2007, and the same is true for Version 2003)
Woo double! What's wrong? All the content in document A is inserted into document B. Are you prompted to ask for a password? No, and it can be changed at will. Hey, the content has been taken out. What can I do? % *!~ & (& % ......
It's another brick. I'm a flash!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.