Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I need to open a word document file using winwordcontrol object using the following code.
I am working on windows form application.


code:
using (WordprocessingDocument OpenDoc = WordprocessingDocument.Open(openFileDialog1.FileName, false))
{
winwordcontrolname.LoadDocument(openFileDialog1.FileName);//error here
}

I am getting an error "Command not available because no document is Open".


Please provide me a solution!
Posted
Updated 17-Dec-13 4:02am
v2
Comments
Debug and see what is the value of openFileDialog1.FileName.

1 solution

Look at what you're doing. You've put the new instance of the document as the target of a using block. Do you know what using does in that context??

When execution leaves the using block the document is Disposed automatically! Yes, there's is no longer any Word document open. If you want the document to stay open, you cannot use it as the target of a using block.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900