Re: re:How To Use Automation to Get and to Set Office Document Pro

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Andrew Hilsher (AndrewHilsher_at_discussions.microsoft.com)
Date: 02/04/05


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" );
> >
> >
>
>
>



Relevant Pages

  • Re: re:How To Use Automation to Get and to Set Office Document Properties
    ... the usual method is just to try it and trap the error. ... I there's no option but to iterate the collection. ... object reference not set to an instance of an object. ...
    (microsoft.public.word.vba.general)
  • AuthorizationContext
    ... System.ServiceModel.OperationContext opx; ... // Iterate through the various claim sets in the AuthorizationContext. ... An unhandled exception of type 'System.ServiceModel.FaultException`1' ... Object reference not set to an instance of an object. ...
    (microsoft.public.dotnet.framework.webservices.enhancements)