none
Manipulating Custom Document Properties using .net RRS feed

  • Question

  • Hi,

     I am trying to retrieve custom document properties of word document using .Net. I can see the ActiveDocument.CustomDocumentProperties returning an object and not able to cast to customproperties object. Not sure how to proceed. Please help.

     

     

    CustomProperties c = currentDocument.CustomDocumentProperties as CustomProperties

    ;


    Thanks Sameer Kamarudeen
    Thursday, April 14, 2011 2:16 PM

Answers

  • Hi Sameer

    CustomDocumentProperties are late-bound into Word which means you can't access them directly in C#. So you have to use GetType().InvokeMember(). See this KB article, for example

    http://support.microsoft.com/kb/303296

    And a search on MSDN or Google will turn up lots of examples.


    Cindy Meister, VSTO/Word MVP
    Thursday, April 14, 2011 2:21 PM
    Moderator

All replies

  • Hi Sameer

    CustomDocumentProperties are late-bound into Word which means you can't access them directly in C#. So you have to use GetType().InvokeMember(). See this KB article, for example

    http://support.microsoft.com/kb/303296

    And a search on MSDN or Google will turn up lots of examples.


    Cindy Meister, VSTO/Word MVP
    Thursday, April 14, 2011 2:21 PM
    Moderator
  • Cindy,

    Thank you... Since C# is too complicated.. I wrote this in VB.Net added solution just for this.. That made my life easier.... Was trying to avoid to add VB.Net project.. But thought this is an eazy shortcut.

     

    Dim properties As DocumentProperties

    properties = currentDocument.BuiltInDocumentProperties

     

    For Each prop As DocumentProperty In properties

    System.Diagnostics.Debug.Print(prop.Name)

     

    Next

    Thanks Sameer Kamarudeen
    Thursday, April 14, 2011 5:11 PM
  • Hi Sameer

    <<Was trying to avoid to add VB.Net project.. But thought this is an eazy shortcut.>>

    Yes, it is :-) Most C# programmers are so anti-VB.NET I've given up suggesting that approach as a workaround. Glad it works for you!


    Cindy Meister, VSTO/Word MVP
    Friday, April 15, 2011 6:36 AM
    Moderator