c# - Using Late-Binding to Automate Word is throwing a MissingMemberException -


i trying access information running microsoft word application using following code..

object appclass = marshal.getactiveobject("word.application"); object documents = appclass.gettype().getproperty("documents"); object count = documents.gettype().invokemember("count", bindingflags.getproperty, null, documents, null); 

when run code tells me that count not found , has thrown missingmemberexception.

can tell me doing wrong?

you didn't reference documents object, getproperty returns propertyinfo. fix:

        object appclass = marshal.getactiveobject("word.application");         object documents = appclass.gettype().invokemember("documents", bindingflags.getproperty, null, appclass, null);         object count = documents.gettype().invokemember("count", bindingflags.getproperty, null, documents, null); 

adding reference microsoft.office.word.interop can make lot less painful.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -