c# - How to handle Word close event from WinForms application? -


i have winforms application , looking way following:

  1. click link create word document blob in database , open it.
  2. block winforms application until word closed.
  3. handle when word closed, check if document changed, , persist changes database.

the problem having not creating word document , opening it, hooking word process know when word has closed. there libraries @ doing or tutorials show how accomplish task?

please see accepted solution, here code used complete task:

protected static string filepath { get; set; }  public static void displaydocument(byte[] documentbytes, string filepath) {     filepath = filepath;      if (documentbytes == null) return;      if (!directory.exists(temp_file_directory))         directory.createdirectory(temp_file_directory);      if (file.exists(filepath)) file.delete(filepath);      try     {         filestream fs = new filestream(filepath, filemode.create);         fs.write(documentbytes, 0, convert.toint32(documentbytes.length));         fs.seek(0, seekorigin.begin);         fs.close();          processstartinfo psi = new processstartinfo(filepath);         process process = process.start(psi);         process.enableraisingevents = true;         process.exited += process_exited;          process.waitforexit();         }     catch (exception e)     {         messagehandler.show(e.message, strings.erroropeningfile);     } }  private static void process_exited(object sender, eventargs e) {     fileinfo fileinfo = new fileinfo(filepath);     if(fileinfo.creationtime.compareto(fileinfo.lastwritetime) < 0)         debug.writeline("file updated, perform database upload here.");  } 

you can wait process close using following code:

process.waitforexit(); 

when word close, can check if file modified , store in database.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -