Solved

Open Password protected Word Document from C#

Posted on 2003-12-04
4
952 Views
Last Modified: 2007-12-19
Hi
 I need to open a word document in C# . The word document has a password.
The code is :

object fileName = openFileDialog1.FileName;
object passwd = "BOSSPASS";
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
string fname;
WordApp = new Word.ApplicationClass();
             
WordApp.Activate();
WordApp.Visible = true;
      
Word.Document aDoc = WordApp.Documents.Open(ref fileName, ref missing,ref readOnly,
ref missing, ref passwd, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible);

I am passing the passwd to the open statements. Still it opens the word document and prompts to enter the password.

Kindly help me to solve this problem.
Thanks in Advance,
sudha



0
Comment
Question by:Sudhabalu
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
_TAD_ earned 200 total points
ID: 9885869



You are missing some references....


<Your Code>
Word.Document aDoc = WordApp.Documents.Open(ref fileName, ref missing,ref readOnly,
ref missing, ref passwd, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible);

<My Code>
Word.Document aDoc = WordApp.Documents.Open(ref docPath, ref missing, ref readOnly,
ref missing, ref password, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible,
ref missing, ref missing, ref missing);

aDoc.Activate();
WordApp.Visible = true;
0
 
LVL 22

Expert Comment

by:_TAD_
ID: 9885886

"you are missing some missing statements"

does the above statement make sense??  

eh... you'll figure it out
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question