Leon H H
Posts: 55
Joined: 2010-04-06
|
I've done this before but for the heck of me I can't recall how...
I have a RichEditControl on in Custom task pane and use pastes some text in it. Now user want to save this text as a Word document. What I need is that user will be prompted with SaveFileDialog for a name and location of a new .docx file, and the file will be saved without opening it in a new Word instance.
Instead, the following code without prompting to the user and opens this file in another Word instance. And I am not sure if the file is saved anywhere on the HD...
[CODE] string filePath = "MyTranscript.docx";
Word.Document doc = null;
try
{
doc = new Word.Document();
doc.Paragraphs[1].Range.InsertParagraphBefore();
doc.Paragraphs[1].Range.Text = TranscriptResultRichEditCtrl.Text;
doc.SaveAs(filePath, FileFormat: WdSaveFormat.wdFormatDocument);
doc.Saved = true;
}
catch (Exception ex)
{
Log.Verbose(ex);
}
finally
{
if (doc != null)
Marshal.ReleaseComObject(doc);
} |
|
Andrei Smolin
Add-in Express team
Posts: 19138
Joined: 2006-05-11
|
Hello Leon,
You should never set doc.Saved unless you do this on purpose. The code fragment above does save a Word document; you can check this by checking doc.Saved. Also, after saving the document, you can close it to prevent showing it up.
Regards from Poland (GMT+1),
Andrei Smolin
Add-in Express Team Leader |
|
Leon H H
Posts: 55
Joined: 2010-04-06
|
Great, thanks.
But why I am not prompted with SaveFileDialog to supply file location and name? I remember that this functionality is embedded in SaveAs function, or am I incorrect? |
|
Andrei Smolin
Add-in Express team
Posts: 19138
Joined: 2006-05-11
|
|