c# - Reading custom fields from a Word document template -


i have written code add custom fields word document template based on information in how add custom properties word doc .net 4?

it works throws exception if field exists. therefore read existing custom fields check there.

i wrote function based on information @ http://msdn.microsoft.com/en-us/library/dhxe2d75(v=vs.110).aspx

but crashes on first iteration of foreach loop.

if there no custom properties not throw exception.

what doing wrong?


a first chance exception of type 'system.invalidcastexception' occurred in unknown module. additional information: unable cast com object of type 'system.__comobject' interface type 'microsoft.office.core.documentproperty'. operation failed because queryinterface call on com component interface iid '{2df8d04e-5bfa-101b-bde5-00aa0044de52}' failed due following error: no such interface supported (exception hresult: 0x80004002 (e_nointerface)).

    private bool propertyexists(word.document document, string propertyname)     {          bool _bret = false;         foreach (microsoft.office.core.documentproperty _property in document.customdocumentproperties)         {             if (_property.name == propertyname)             {                 _bret = true;             }         }          return _bret;     } 


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -