Hello
In my application I catch the DocumentBeforeSave event displaying a dialog box giving the user 3 options: "save in a external archiving system" - "save on disk" - "cancel".
If the user presses the "save on disk" I display the saveDialog. I hav two questions regarding this:
1: The first dialog box is still visible even though I close it in my code.
2: The saveDialog works fine - it seems... But no documents are saved. I guess this has to do with the parameter Cancel = true in the DocumentBeforeSave event - how can I fix this
neoret

Show the savdialog after DocumentBeforeSave
vefan
Hello there
I also have a problem with SaveAs file dialog from word 2003
I wrote the following code
private
void oWord_DocumentBeforeSave(Microsoft.Office.Interop.Word.Document Doc, ref bool SaveAsUI, ref bool Cancel){
try{
MessageBox.Show ("Saving document", "DocumentSave event",
MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBox.Show("doc path:"+Doc.FullName+ "val:"+SaveAsUI.ToString() +" cancel:"+Cancel.ToString());
object omissing = System.Reflection.Missing.Value ; object readOnly= false;Word.Dialog dlg=oWord.Dialogs[Word.WdWordDialog.wdDialogFileSaveAs];
object timeOut=null; int returnVal=dlg.Display(ref timeOut);MessageBox.Show("return value="+returnVal);
if (returnVal!=0) { //nu s-a apasat cancelMessageBox.Show("comandName:"+dlg.CommandName);
object prop= dlg.GetType().InvokeMember("Name", System.Reflection.BindingFlags.GetProperty |System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance,
null, dlg,null,System.Globalization.CultureInfo.InvariantCulture);MessageBox.Show("fileName I hope: name="+ prop.ToString());
object filePath=prop.ToString();Doc.SaveAs(
ref filePath,ref omissing,ref omissing,ref omissing,ref omissing,ref omissing,ref readOnly,ref omissing,ref omissing,ref omissing,ref omissing,ref omissing,ref omissing,ref omissing,ref omissing,ref omissing);}
SaveAsUI =
false;}
catch(Exception e){
MessageBox.Show("Error saveAs: "+e.Message + " cause:"+e.StackTrace);
}
}
and in msdn there is the specification "SaveAsUI True to display the Save As dialog box"
my problem is that the SaveAs file dialog is displaying twice
please can you give me any help
my best regard
George
lathajith
Hi George
You need to put the SaveAsUI = false at start of the code, I think. Here's a sample (VBA) that works for me.
' Dim dlg As Word.Dialog
' Dim retval As Long
'
' SaveAsUI = False
' 'MsgBox Doc.FullName
' Set dlg = app.Dialogs(wdDialogFileSaveAs)
' retval = dlg.Display
' If retval <> 0 Then
' Doc.SaveAs FileName:=dlg.Name
' End If
' Cancel = True
lbeham
thanks a lot for your replay
but
I was trying to write in my method DocumentBeforeSave just
SaveAsUI=false
and the SaveAs file dialog still shows
I also decompile the Microsoft.Office.Interop.Word.dll and in the Microsoft.Office.Interop.Word.il file you will see that the signature of this method is something like this :
void DocumentBeforeSave([in] class Microsoft.Office.Interop.Word.Document marshal( interface) Doc,
[in] bool& SaveAsUI,
[in] bool& Cancel)
so... I am thinking that word did not care about my modification on this flag
George
Sayhan
void OnSaveAsButtonClick(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
try
{
this.Visible = false;
if (sfd.ShowDialog() == DialogResult.OK)
{
//TODO: call the Word SaveAS() method here
//passing it the filename entered by the user
//in the SaveAsDialog
}
}
finally
{
sfd.Dispose();
this.Close();
}
}
The SaveFileDialog does not automatically handle saving the document or anything, it merely provides a UI from which the user can enter the filename they want to "Save as", you still have to manually code the rest of the logic ...
Hope this helps.
D.
mhagman
Hi
I want to catch Word Saving event and do my custom saving logic of my application. My application is having a Save toolbar item on the form.
check the sample code
void Application_DocumentBeforeSave(Word.Document Doc, ref bool SaveAsUI, ref bool Cancel) Cancel = true;form.Save();
}
actually i am opening an existing word document.
because cancel is set to true. word document is closed without saving it..
its assuming that its a new document i am opening but actually its a existing document which is being modified.
help needed
Thanks
Jyothi
Steven Mooses
Hello George.
This is a tricky thing to do in word. The problem is that when you say Doc.SaveAs the save event is thrown again and is catched by your eventhandler. That is why you see the savebox twice I think. In excel you have a function that allows you to turn off the event catching... That was very helpful when doing this.
To manage to do this in Word I had to do this in an alternative way. I'll try to explain:
- I have my evenhandler that catches the save event
- I have another method that saves the document. At the very start of this method I set a proprty on the word document to be TRUE.
- In my eventhandler the first thing I do is check this parameter. If it is TRUE I do nothing - just set the cancel = true;
Hope this helped you on the way :)
AndrejS
1: I tried setting visible = false before I create the saveFileDialog. This doe not help any. Is there any refresh comand
2: To call the savemethod I start the saveFileDialog this way: SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.ShowDialog(); After that I don't do anything... Maybe that's the problem. I thought the saveFileDialog was a built in form that handled all the events itself...
Thanks for any help you can give me :)
neoret
shview
1. I'm guessing that first dialog still displays because you're showing (spawning) the second dialog from within the first. If you plan on doing it that way, then hide the first dialog (visible = false;)
2. Not entirely certain you're second statement is correct ... how are you saving the document out What are the parameters you're using to call the save method
longle37
BugInfested
Hi friend
am new to vsto Development ! My task is I am able to catch a word document before save it
is it possible
if it's possible pls give me an idea for me and sample code r Useful resource
it's urgent
thanks