C
cooldoger
I want save word file in my format, so I catch the
Microsoft.Office.Interop.Word.ApplicationEvents4_DocumentBeforeCloseEventHandler
and implement it, but in the handler "savefiledialog" cannot be used--nothing
shown on the window.
here is the part of code:
....
Word.Application WordApp = new Word.ApplicationClass();
....
wordDoc = WordApp.Documents.Add(ref missing, ref missing, ref missing, ref
missing);
....
wordDoc.Application.DocumentBeforeClose += new
Microsoft.Office.Interop.Word.ApplicationEvents4_DocumentBeforeCloseEventHandler(Application_DocumentBeforeClose);
....
public void Application_DocumentBeforeClose(Word.Document doc, ref bool
cancel)
{
Process processWord = new Process();
Process[] processCollection =
Process.GetProcessesByName("WINWORD");
processWord = processCollection[0];
DialogResult drTemp = MessageBox.Show(new
WindowWrapper(processWord.MainWindowHandle), "save the file?", "file",
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
if(drTemp==DialogResult.Yes)
{
cancel = false;
SaveFileDialog sfdTemp = new SaveFileDialog();
sfdTemp.DefaultExt = ".boc";
if (
sfdTemp.ShowDialog(new
WindowWrapper(processWord.MainWindowHandle)) == DialogResult.OK //the problem
is here
)
{
MessageBox.Show(sfdTemp.FileName);
//do something else
}
}
else if(drTemp==DialogResult.No)
{
cancel = false;
object saveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;
object originalFormat =
Word.WdOriginalFormat.wdOriginalDocumentFormat;
object routeDocument = false;
doc.Close(ref saveChanges, ref originalFormat, ref
routeDocument);
}
else
{
cancel = true;
return;
}
}
Microsoft.Office.Interop.Word.ApplicationEvents4_DocumentBeforeCloseEventHandler
and implement it, but in the handler "savefiledialog" cannot be used--nothing
shown on the window.
here is the part of code:
....
Word.Application WordApp = new Word.ApplicationClass();
....
wordDoc = WordApp.Documents.Add(ref missing, ref missing, ref missing, ref
missing);
....
wordDoc.Application.DocumentBeforeClose += new
Microsoft.Office.Interop.Word.ApplicationEvents4_DocumentBeforeCloseEventHandler(Application_DocumentBeforeClose);
....
public void Application_DocumentBeforeClose(Word.Document doc, ref bool
cancel)
{
Process processWord = new Process();
Process[] processCollection =
Process.GetProcessesByName("WINWORD");
processWord = processCollection[0];
DialogResult drTemp = MessageBox.Show(new
WindowWrapper(processWord.MainWindowHandle), "save the file?", "file",
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
if(drTemp==DialogResult.Yes)
{
cancel = false;
SaveFileDialog sfdTemp = new SaveFileDialog();
sfdTemp.DefaultExt = ".boc";
if (
sfdTemp.ShowDialog(new
WindowWrapper(processWord.MainWindowHandle)) == DialogResult.OK //the problem
is here
)
{
MessageBox.Show(sfdTemp.FileName);
//do something else
}
}
else if(drTemp==DialogResult.No)
{
cancel = false;
object saveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;
object originalFormat =
Word.WdOriginalFormat.wdOriginalDocumentFormat;
object routeDocument = false;
doc.Close(ref saveChanges, ref originalFormat, ref
routeDocument);
}
else
{
cancel = true;
return;
}
}