locked
Disable auto-save RRS feed

  • Question

  • Hi,

    is it possible to disable auto-save in VSTO for ActiveDocument or for all documents in general?

    Monday, February 15, 2016 2:53 PM

Answers

  • Hello,

    You can handle the BeforeSave event of the Document class which is fired before the document is saved. To prevent the document from being saved, set the Cancel argument of the provided CancelEventArgs object to true.

    private void DocumentBeforeSave()
    {
        Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
        vstoDoc.BeforeSave += new Microsoft.Office.Tools.Word.SaveEventHandler(ThisDocument_BeforeSave);
    }
    
    void ThisDocument_BeforeSave(object sender, Microsoft.Office.Tools.Word.SaveEventArgs e)
    {
        if (System.Windows.Forms.MessageBox.Show("Do you want to save the document?", "BeforeSave",
            System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
        {
            e.Cancel = true;
        }
    }

    • Marked as answer by Lugaxx Monday, February 15, 2016 4:43 PM
    Monday, February 15, 2016 3:54 PM

All replies

  • Hello,

    You can handle the BeforeSave event of the Document class which is fired before the document is saved. To prevent the document from being saved, set the Cancel argument of the provided CancelEventArgs object to true.

    private void DocumentBeforeSave()
    {
        Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
        vstoDoc.BeforeSave += new Microsoft.Office.Tools.Word.SaveEventHandler(ThisDocument_BeforeSave);
    }
    
    void ThisDocument_BeforeSave(object sender, Microsoft.Office.Tools.Word.SaveEventArgs e)
    {
        if (System.Windows.Forms.MessageBox.Show("Do you want to save the document?", "BeforeSave",
            System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
        {
            e.Cancel = true;
        }
    }

    • Marked as answer by Lugaxx Monday, February 15, 2016 4:43 PM
    Monday, February 15, 2016 3:54 PM
  • @Eugene Astafiev

    Is there maybe a way to determine how the save operation has been invoked? (manually, via auto-save, etc.)

    Wednesday, February 17, 2016 1:09 PM
  • Hi Lugaxx,

    >>Is there maybe a way to determine how the save operation has been invoked? (manually, via auto-save, etc.)

    For this new issue, I suggest you post a new thread for this, and there would be more community members to help you.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, February 18, 2016 8:36 AM