Re: re:How To Use Automation to Get and to Set Office Document Pro
From: Andrew Hilsher (AndrewHilsher_at_discussions.microsoft.com)
Date: 02/04/05
- Next message: Jezebel: "Re: I was given this macro from this group"
- Previous message: Steved: "Re: I was given this macro from this group"
- In reply to: Jezebel: "Re: re:How To Use Automation to Get and to Set Office Document Properties"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 3 Feb 2005 22:33:06 -0800
Thanks Leigh and Jez,
That worked!
=o)
"Jezebel" wrote:
> As Leigh says, the usual method is just to try it and trap the error. If you
> don't like that, I there's no option but to iterate the collection.
>
>
> "Andrew Hilsher" <Andrew Hilsher@discussions.microsoft.com> wrote in message
> news:D47F808D-0ADB-4F8B-82F4-F2F84E7F13E6@microsoft.com...
> >I have a Word addin in C# that gets and sets Document properties. I have
> > used the example in the "How To Use Automation to Get and to Set Office
> > Document Properties with Visual C# .NET" example. (
> > http://support.microsoft.com/?kbid=303296 ) My problem is, If i try and
> > read
> > a property such as "Category" that is not set yet, it is null. I get an
> > error at runtime, object reference not set to an instance of an object.
> >
> > The example they give in the article above reads the "Author" property
> > which
> > is never null. How can I check to see if it is null before I read it and
> > get
> > this error? Here is the sample code from the article.
> >
> > Thanks in advance,
> > Andrew
> > ahilsher@yahoo.com
> >
> >
> > //Get the Author property and display it.
> > string strIndex = "Author";
> > string strValue;
> > object oDocAuthorProp = typeDocBuiltInProps.InvokeMember("Item",
> > BindingFlags.Default |
> > BindingFlags.GetProperty,
> > null,oDocBuiltInProps,
> > new object[] {strIndex} );
> > Type typeDocAuthorProp = oDocAuthorProp.GetType();
> > strValue = typeDocAuthorProp.InvokeMember("Value",
> > BindingFlags.Default |
> > BindingFlags.GetProperty,
> > null,oDocAuthorProp,
> > new object[] {} ).ToString();
> > MessageBox.Show( "The Author is: " + strValue,"Author" );
> >
> >
>
>
>
- Next message: Jezebel: "Re: I was given this macro from this group"
- Previous message: Steved: "Re: I was given this macro from this group"
- In reply to: Jezebel: "Re: re:How To Use Automation to Get and to Set Office Document Properties"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|