how to move a word document with c#
-
hi to all, i have to move a word document from one directory to another, but if the document is open i can't move it. how can i close the document before i move it (i have no instance of word to this document so i can't use the method close(), all i have is the path and the document name) best regards and thanks in advance fady
-
hi to all, i have to move a word document from one directory to another, but if the document is open i can't move it. how can i close the document before i move it (i have no instance of word to this document so i can't use the method close(), all i have is the path and the document name) best regards and thanks in advance fady
Well you can first try to move it, if it doesn't move, you can throw some messagebox response asking the user to close the Word file. You can also automatically close the word file, by using the Process class. Something like
Process[] p = System.Diagnostics.GetProcessesByName("winword.exe"); for (int i = 0; i < p.length ;i++) { p[i].Close(); //or more brutally p[i].Kill(); }