Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

controlling word documents from within a c# windows application

Posted on 2006-06-27
3
Medium Priority
?
395 Views
Last Modified: 2008-02-01
Hi Guru's

I'm developing an c# windows application where part of the procedure is to create word procesesed documents and store them in SQL DB.  I'm using Word 11.0 with interop facilities.  I've managed to trap the word's quit event from within C# so that if the user quits word, C# will know about this and therefore drop the reference to it.  I was hoping to retrieve the doc.Contents.Text stuff before it actually closes word, but this doesn't, as it looses the document first, then passes to the quit function.

I then found the DocumentBeforeSave event, which will call my defined function before word actually tries to save it (if changes were made, a prompt appears).

Ok, so now I'm trapping the BeforeSave, retrieving the contents of the word document to put into a text SQL database field, along side a couple of other bits and pieces of information.  I was then hoping for word just to quit (without the save file dialog prompted), but I get the error - word cannot quit while the file dialog box is open.

Is there anyway round this? How can I stop that file dialog appearing, still get the contents of the word doc and close it without any prompts  (I'm using get_XML, InsertXML).

Many thanks for any help

Toby
0
Comment
Question by:daviesgroup
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
sumix earned 1000 total points
ID: 16998919
DocumentBeforeSave event is raised after you chose 'Yes' on the message dialog that appears when you try to close Word and there are changes in the document. So you cannot stop this dialog from inside this event handler. Instead you could use DocumentBeforeClose event, and in its event handler call Doc.Save() method and do whatever you want with your document. This way the document will be automatically saved when you close Word, without any other dialog.
0
 

Author Comment

by:daviesgroup
ID: 16999251
Ok, I'll try that now....
0
 

Author Comment

by:daviesgroup
ID: 16999554
Nice one, that done the job nicely - thanks a lot!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

604 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