none
How to retrieve the current folder from the Word DialogFileSave dialog before the document is saved? RRS feed

  • Question

  • Hi, I have a Visual Studio 2010 Word 2007 Add-in project. 

    My code displays the Word DialogFileSave dialog letting the user select a file name and location. The Name property of the dialog only returns me the name of the file, but I need to know the full path before the file is actually saved.

    Now when I call the SaveAs method of the active Word document the file is stored at the location that the user selected in the DialogFileSave dialog. How does the SaveAs method know where to store the file? So my guess is that the selected location is stored somewhere and hopefully can be retrieved.

    Is there a way to get the current folder before the file is saved?

    dynamic dialog = this.Application.Dialogs[Microsoft.Office.Interop.Word.WdWordDialog.wdDialogFileSaveAs];
    
    dynamic result = dialog.Display(ref missing);
    
    if (result != 0)
    {
        // At this place, before the file is saved I need to know the full 
        // path of the document that will be saved in the next statement!
    
        document.SaveAs(dialog.Name, dialog.Format);
    }
    

    Thanks in advance!

    Michel Miranda

    Thursday, April 4, 2013 5:52 PM

Answers

  • Hi Rich, thank you for your response.

    I was using the dialog from the Microsoft.Office.Interop.Word namespace. The dialog in the Microsoft.Office.Core namespace suggested by you supports the functionality that I am looking for.

    I am a little bit confused about the differences between the two dialogs and when to use them.

    I will definitely mark your response as an answer.

    Best Regards,

    Michel Miranda

    Friday, April 5, 2013 5:08 AM

All replies

  • Hi Michael,

    Before you let the save as run you trap the selected item like the following VBA example

        With Application.FileDialog(msoFileDialogSaveAs)
            .Show
            Debug.Print .SelectedItems.Item(1)
            .Execute
        End With
    
    Hope this helps

    Kind Regards, Rich ... http://greatcirclelearning.com

    Friday, April 5, 2013 3:01 AM
  • Hi Rich, thank you for your response.

    I was using the dialog from the Microsoft.Office.Interop.Word namespace. The dialog in the Microsoft.Office.Core namespace suggested by you supports the functionality that I am looking for.

    I am a little bit confused about the differences between the two dialogs and when to use them.

    I will definitely mark your response as an answer.

    Best Regards,

    Michel Miranda

    Friday, April 5, 2013 5:08 AM
  • Hi Michael,

    I can't recall when I switched from using the Word namespace dialogs to the Office dialogs, but I use the Office dialogs now in all my apps.

    Glad to hear it helped


    Kind Regards, Rich ... http://greatcirclelearning.com

    Friday, April 5, 2013 12:06 PM