copying MAPI properties

N

Nikolas

Hi,

I am using C# in VS 2005 and VSTO SE Beta.

My aim is to create a new MailItem that has some of the same properties of
another MailItem. Using MAPI you could do it using the IMAPIProp::CopyTo()
function and specifying which properties you wanted to copy from one MailItem
to another. Is there a way of doing this with the new Outlook object model?

Note that the new MailItem does not have all the properties of the old
MailItem. Is that an issue? I understand that some of the properties have a
read only access but still there must be a way of changing them like there is
in MAPI.

I tried using PropertyAccessor and copy each property one by one but failed.
Here is what I do:

string propertyName = "http://schemas.microsoft.com/mapi/proptag/0x0E070003"

MailItem newMailItem = this.Application.CreateItem(OlItemType.olMailItem) as
MailItem;

int value = oldMailItem.PropertyAccessor.GetProperty(propertyName);
newMailItem.PropertyAccessor.SetProperty(propertyName, value);

The last line throughs the exception. This specific property is computed
property and you cant even set it using OutlookSpy but I have some code using
(as mentioned above) IMAPIProp::CopyTo() function and does copy it to the new
message.

Any help would much appreciated.
 
K

Ken Slovak - [MVP - Outlook]

CopyTo is different, it's just copying properties that already exist, not
setting computed properties. You can't do what you want using the
PropertyAccessor or anything else in the OOM unless you copy an entire
message. Trying to set individual properties just won't work if they're
computed properties, as I said in response to your original post.
 

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