View Single Post
 
Old 08-22-2014, 02:42 AM
chetan rajakumar chetan rajakumar is offline Windows 7 32bit Office 2010 32bit
Novice
 
Join Date: Aug 2014
Posts: 1
chetan rajakumar is on a distinguished road
Default ThisAddIn.Application.Documents.Open() methods opens new word instance even though the active docume

Title:
ThisAddIn.Application.Documents.Open() methods opens new word instance even though the active document is empty.

Hi,

I have created a Ribbon for MS Word(2010). On click of ribbon button(Download button) I have to open the document specified in the code. If active document(present document) is empty then it should open in same word instance and if the active document contains some text it should open in new word instance.

I have the below piece of code which does this.
Code:
private static void OpenWordDocument(byte[] content, string tempfile)
{
System.IO.File.WriteAllBytes(tempfile, content);
object missing = System.Reflection.Missing.Value;
object fileName = tempfile;
object readOnly = true;
object isVisible = true;
object confirmConversions = true;
object addToRecentFiles = false;
object saveas = false;
Microsoft.Office.Interop.Word.Document wordDoc = Globals.ThisAddIn.Application.Documents.Open(
ref fileName,
ref confirmConversions,
ref readOnly,
ref addToRecentFiles,
ref missing,
ref missing,
ref missing,
ref missing,
ref missing,
ref missing,
ref missing,
ref isVisible,
ref missing,
ref missing,
ref missing,
ref missing);
ThisAddIn.Application.ActiveDocument.ActiveWindow.DisplayHorizontalScrollBar = true;
ThisAddIn.Application.ActiveDocument.ActiveWindow.ActivePane.View.Type = WdViewType.wdPrintView;
}
Issue: The functionality does not work expected in below scenario:
1. Open saved word document which has some content in it.
2. Click on File tab -> New -> Blank document.
3. In this blank document, click on my Addin's download button which should download the content and display it in Word document.
Since we have opened new blank document and this document is empty. It should have opened the downloaded content in this empty document itself instead it is getting displayed in new word instance.

However the functionality works as expected when I first open the new document instead of saved word document in the first go.i.e, in below scenario:
1. Go to Start --> Select MS Word 2010.
2. In this blank document, click on my Addin's download button.
This action downloads the content and display it in same blank document.

Please help me to solve the above issue, thanks in advance.


Regards, Chetan.
Reply With Quote