c# - How to handle Word close event from WinForms application? -
i have winforms application , looking way following:
- click link create word document blob in database , open it.
- block winforms application until word closed.
- 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
Post a Comment