Word Document Properties - Invalid Cast

F

Fred Woolsey

My question is as follows:

The following code in a static utility method---

[snip]
return ((Office.DocumentProperties)doc.CustomDocumentProperties)[name].Value;
[/snip]

---works just peachy when called from within a C# Word template
(document-level) customization, but throws a COM "Invalid Cast" exception
when called from the Windows Forms application that opened/created the
document with the associated document-level customization (created, that is,
by the Application.Documents.Add(customizedTemplateName) method). In both
cases the utility method is in a static class in a referenced project.

Is something lost when going from doc = VSTO ThisDocument.InnerObject within
a VSTO doc-level customization to doc = Word.DocumentClass.ThisDocument in a
..NET forms application?

Thanks
 

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