What is the recommendet way to read/write a user defined Field (Named Property) in the MailItem Obje

  • Thread starter Michael Schmitz
  • Start date Views 2,320
Status
Not open for further replies.
M

Michael Schmitz

Hello NG,

I am very new to Outlook2007 and VSTO (Visual Studio 2008)

in a mail i have a user defined Named Property "UID"

the DASL is

http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/UID

(I used outlookspy to get this)

At the moment I'am looping through all ItemProperties and search for

a Property with the Name "UID" to read/write to that property.

Is their a better way to directly access such a user defined property?

maybe something like: string foo = (string) mail.Properties["UID"]; ?

I've read something about the Outlook.PropertyAccessor, but I'am not

aure if this is the normal way to read/write a user defiened field.

below is a snippet of a csharp code I'am using at the moment.

CodeSnippet:

############################################

private void On_btnSave_Click(object sender, EventArgs e)

{

Outlook.MailItem mail;

Outlook.ItemProperties properties;

try

{

if (this.OutlookItem is Outlook.MailItem)

{

mail = (Outlook.MailItem)this.OutlookItem;

properties = mail.ItemProperties;

// aender den Betreff wie gewuenscht ab

mail.Subject = this._txt1.Text;

// suche das UID Propertie!

foreach (Outlook.ItemProperty xProperty in properties)

{

if (xProperty.Name == "UID")

{

xProperty.Value = this._txt2.Text;

break;

}

}

mail.Save();

}

}

finally

{

mail = null;

properties = null;

}

}
 
D

Dmitry Streblechenko

Have youi looked at MailItem.PropertyAccessor?

Dmitry Streblechenko (MVP)

-

"Michael Schmitz" <spam@gmx.net> wrote in message

news:O4uUHxrwJHA.956@TK2MSFTNGP03.phx.gbl...
> Hello NG,

> I am very new to Outlook2007 and VSTO (Visual Studio 2008)

> in a mail i have a user defined Named Property "UID"

> the DASL is
> http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/UID
> (I used outlookspy to get this)

> At the moment I'am looping through all ItemProperties and search for
> a Property with the Name "UID" to read/write to that property.

> Is their a better way to directly access such a user defined property?

> maybe something like: string foo = (string) mail.Properties["UID"]; ?
> I've read something about the Outlook.PropertyAccessor, but I'am not
> aure if this is the normal way to read/write a user defiened field.

> below is a snippet of a csharp code I'am using at the moment.
> CodeSnippet:
> ############################################
> private void On_btnSave_Click(object sender, EventArgs e)
> {
> Outlook.MailItem mail;
> Outlook.ItemProperties properties;

> try
> {

> if (this.OutlookItem is Outlook.MailItem)
> {
> mail = (Outlook.MailItem)this.OutlookItem;
> properties = mail.ItemProperties;

> // aender den Betreff wie gewuenscht ab
> mail.Subject = this._txt1.Text;

> // suche das UID Propertie!
> foreach (Outlook.ItemProperty xProperty in properties)
> {
> if (xProperty.Name == "UID")
> {
> xProperty.Value = this._txt2.Text;

> break;
> }
> }
> mail.Save();
> }
> }
> finally
> {
> mail = null;
> properties = null;
> }
> }

>
 
Status
Not open for further replies.
Top