I am developing a custom ribbon in Microsoft Word document. I intend to override the save functionality by disabling it and save the document programmatically.
I have added DocumentBeforeSave event Handler to save the document. Here is the part of the code to save the document
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Globals.ThisAddIn.Application.DocumentBeforeSave += new Word.ApplicationEvents4_DocumentBeforeSaveEventHandler(this.Application_DocumentBeforeSave);
}
public void Application_DocumentBeforeSave(Word.Document document, ref bool saveAsUI, ref bool cancel)
{
String destFolder = @"D:\report\tempFolder\";
Random rnd = new Random();
String fileName = "Temp_" + rnd.Next(1000, 9999).ToString() + ".docx";
var destFile = System.IO.Path.Combine(destFolder, fileName);
document.SaveAs2(destFile);
}
Any idea how to do that?