0

iam playing around with the NetOffice Wrapper and trying to access the Word Editor of an Outlook Mailitem.

Previously i was using

MailItem mItem = (MailItem)inspector.CurrentItem;
Microsoft.Office.Interop.Word.Document docx = mItem.GetInspector.WordEditor;
Microsoft.Office.Interop.Word.Selection selected = docx.Windows[1].Selection;

which is working. Now with NetOffice i was trying

Word.Document docx = mItem.GetInspector.WordEditor;

which tells me that object cannot be converted to Word.Document. using

Word.Document docx = mItem.GetInspector.WordEditor as Word.Document;

is telling NetOffice.WordApi.Document cannot be embedded.

Does anybody know, how i can access the WordEditor with NetOffice. Thank you for your help.

Stefan

Stefan Weber
  • 115
  • 1
  • 1
  • 10

2 Answers2

0

In case anyone ever comes across this again like I did, the answer to his question is to select the [NetOffice]WordApi reference in Visual Studio, and change "Embed Interop Types" property to False.

Image

Jeff
  • 41
  • 3
-1

Stefan,

Why do you need to use NetOffice assembly. I'd recommend using a clear code and release underlying COM objects instantly. Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook object when you have finished using it. This is particularly important if your add-in attempts to enumerate more than 256 Outlook items in a collection that is stored on a Microsoft Exchange Server.

 mItem.GetInspector.WordEditor

Note, the GetInspector method of the Inspector class returns an instance of the Inspector class which should be released as well. Don't use multiple dots in the single line of code. Or underlying COM objects will be left unreleased.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45