EagleWizard

Code Snippet

Outlook.PropertyAccessor pa;

pa = m_olMail.PropertyAccessor;

string propname = "http://schemas.microsoft.com/mapi/proptag/0x0030001E";

string sprop = pa.GetProperty(propname).ToString();

I'm using this code to access a property of a mail object in Microsoft Outlook 2007, but I always get a DISP_E_TYPEMISMATCH error

"Message "Type komt niet overeen. (Uitzondering van HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))" string"

I tried everything, but I can't seem to find the problem. When I use object I get the same problem.

Code Snippet

object test = pa.GetProperty(propname);

Convert.ToString() also doesn't work. And as last hope I tried to use the BinaryToString() method, but no result.

Anybody that can help me Cause I'm starting to get an idea it's an internal problem of Outlook itself.

Here is some information I used.

GetProperty Method

Best Practice Getting and Setting Properties

PropertyAccessor Object




Re: Visual Studio Tools for Office PropertyAccessor.GetProperty Method (C#)

X4U

Hello EagleWizard,

I can reproduce - but maybe the property that you want to retrieve is not a string

can you tell us what Infromation you want to retrieve.

For wich property stands "0x0030001E"

Greets, Helmut






Re: Visual Studio Tools for Office PropertyAccessor.GetProperty Method (C#)

EagleWizard

X4U wrote:

For wich property stands "0x0030001E"

The property is a custom property that I give to a MailItem.

The value has to be a CustomerId, so I can get more detailed information about the sender of the mail.

I'm sure that it is a string, cause I explored the MailItem with OutlookSpy.

Tag num: 0x0030001E

Tag sym: 0x0030

Type: PT_STRING8

Value: 2

DASL: http://schemas.microsoft.com/mapi/proptag/0x0030001E






Re: Visual Studio Tools for Office PropertyAccessor.GetProperty Method (C#)

X4U

Hello, EagleWizard -

i tried to set the property and I get the same error.

What I want to know is: How do you come to exactly this ID

Are you sure that this is a valid id

Are you sure this ID isn't used from MAPI internals

If you want to store a simple string or ID I would recommend to use the Mileage field.

As I know in MailItems this field is unused and easier to handle.

Greets, Helmut






Re: Visual Studio Tools for Office PropertyAccessor.GetProperty Method (C#)

EagleWizard

The Id was a free number and I'm sure it's correct cause I explored it with OutlookSpy.

If you develop for Outlook it's a very handy program.

Now I fixed it with Redemption again. When you want to deploy an add-in you first have to sign all the assemblies.

The problem with the Redemption DLL was that it was a third partie DLL, so it wasn't possible to sign it.

Now I just put the DLL in the Bin folder of the program and use Redemption by using Reflection.

With Reflection you can load external DLL's that don't have to be signed.

It's more work than when I would use the PropertyAccessor, but since I can't seem to find the problem it took me less time.

If their are peoply who know why this error occures, I'm interested in the answer..

And thanks to Helmut for your previous posts






Re: Visual Studio Tools for Office PropertyAccessor.GetProperty Method (C#)

X4U

Hi EagleWizard,

the last that I want to say is:

If you use the TLBImp tool to create an PIA for the redemption dll manually - you could strong name it.

So - all references are strong-named and you don't have to use latebinding.

But the PropAccessor needs some investigation again.

Hope this helps,

greets, Helmut






Re: Visual Studio Tools for Office PropertyAccessor.GetProperty Method (C#)

EagleWizard

X4U wrote:

If you use the TLBImp tool to create an PIA for the redemption dll manually - you could strong name it.

So - all references are strong-named and you don't have to use latebinding

Is it possible to show me an example of how to do it Cause you need a tlb file when you want to use TLBImp.

And Redemption only has a dll. I tried to generate a tlb file with Regasm, but I got an error.

Thanks in advance






Re: Visual Studio Tools for Office PropertyAccessor.GetProperty Method (C#)

X4U

Hello EagleWizard,

open a VisualStudio Command prompt.

cd to your Redemption installation directory, usual C:\program files\redemption

if you don't have a keyfile - create one:

sn -k myKey.snk

them create a PIA for Redemption dll:

tlbimp redemption.dll /keyfile:myKey.snk /outStick out tongueIA.Redemption.dll

will produce the PIA file.

Now go to your project, remove the reference to Redemption,

add a reference to the PIA.Redemption.dll to your project.

That should do the trick.

You could also give an explicit namespace when using the tlbimp tool.

Deployment:

You have to deliver the Redemption.dll to the client PC and register it - and put the generated PIA file into the output directory.

Hope this helps,

greets Helmut






Re: Visual Studio Tools for Office PropertyAccessor.GetProperty Method (C#)

EagleWizard

Worked like charm!!

Thanks for all the help I got from you






Re: Visual Studio Tools for Office PropertyAccessor.GetProperty Method (C#)

EagleWizard

When I was just so happy that everything worked, I got another problem.

I was able to tag a mail with a CustomerId, but when I forward the mail to a college of mine

the tag isn't added in the mail.

Any idea's what the problem could be






Re: Visual Studio Tools for Office PropertyAccessor.GetProperty Method (C#)

X4U

Hello EagleWizard,

this works only if you are using the MailItem within on e and the same Exchangeserver.

Doesn't work with SMTP & POP and between different Exchangeservers.

Also if you set the mapiproperty I can remember that you have to trick outlook that some normal property has changed and then call save.

e.g.

item.Subject = item.Subject

If you want to keep a property between exchangeservers or SMTP - you must use an SMTP Header for that.

Hope this helps,

greets, Helmut






Re: Visual Studio Tools for Office PropertyAccessor.GetProperty Method (C#)

EagleWizard

Thanks again, you saved me a lot of time. It's too bad that it doesn't work with POP3 though.

Maybe that I'll look for a workaround, but I don't count on finding one cause your better acquinted with the technologie then I am.

Greetz