Solved

controlling word documents from within a c# windows application

Posted on 2006-06-27
3
373 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
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
sumix earned 250 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now