obtaining the print dialog using reflection

T

tonegawa

I'm using word automation, and I need to correct the old code, in order to
use just the reflection, and not the direct reference to the office libraries
from visual studio.

The old code had:

varDlg =
varWord.Application.Dialogs[Microsoft.Office.Interop.Word.WdWordDialog.wdDialogFilePrint]

I don't know how to invoke the [] operator using reflection.

(also Microsoft.Office.Interop.Word.WdWordDialog.wdDialogFilePrint is not an
int, but an enum type)
 
T

tonegawa

problem solved!!!

These things are called indexed Properties

if you can index a property with [], this property has its own property call
"Item" by default. You can specify the index in the second argument of the
GetValue() method


This is the correct code:

PropertyInfo pi =
(varWord.GetType().Assembly.GetType("Microsoft.Office.Interop.Word.Dialogs")).GetProperty("Item");
varDlg = pi.GetValue(objDialogEnum, new Object[] {
objDialogEnumId });
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top