1

Good Day!

I want to know if it's possible to show SaveFileDialogue when saving .docx file using Novacode DocX?

Sample:

string fileName = @"D:\Users\John\Documents\DocXExample.docx";
var doc = DocX.Create(fileName);
doc.InsertParagraph("This is my first paragraph");        
doc.Save();

Where shoud I put the SaveFileDialogue code?

Many Thanks!

2 Answers2

1

Put saveFileDialog1.ShowDialog(); inside some button event handler which lets the user save the document. Double-click on the SaveFileDialog icon in your Visual Studio designer window as well to add the FileOk event handler and within event handler, put your code like this:

    private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
    {
       var doc = DocX.Create(saveFileDialog1.FileName);
       doc.InsertParagraph("This is my first paragraph");        
       doc.Save();
    }

Hope it helps!

M. Adeel Khalid
  • 1,786
  • 2
  • 21
  • 24
0

To do this:

private void btn_approve_Click(object sender, EventArgs e)
{
 saveFileDialog1.Title = "Save As";
 saveFileDialog1.Filter = "DocX|*.docx";

   if (saveFileDialog1.ShowDialog() == DialogResult.OK)
   {
      var doc = DocX.Create(saveFileDialog1.FileName);
      doc.InsertParagraph("This is my first paragraph");        
      doc.Save();                         
   }
}