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

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;

}

}
 
S

Sue Mosher [MVP]

You should be able to use ItemProperties.Item("UID") or

UserProperties.Item("UID").

Sue Mosher

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

news:OeRkqorwJHA.1208@TK2MSFTNGP04.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?
 
M

Michael Schmitz

"Sue Mosher [MVP]" <suemvp@turtleflock.com> schrieb im Newsbeitrag

news:O3tMAyrwJHA.4592@TK2MSFTNGP06.phx.gbl...
> You should be able to use ItemProperties.Item("UID") or
> UserProperties.Item("UID").


Thanks Sue that was the right hint to point me to a direction.

My code looks now like this, I guess the above only works for

VB.NET?

Regards

Michael (I got your Book allready ;))!

codesnipet:

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

mail = (Outlook.MailItem)this.OutlookItem;

this._txt1.Text = "Read:" + mail.Subject;

try

{

this._txt2.Text = mail.ItemProperties["UID"].Value.ToString();

}

catch

{

this._txt2.Text = "???";

}
 
S

Sue Mosher [MVP]

I have no idea. I write code only for VB languages. Your best reference is

the PIA documentation on MSDN; perhaps the example at

http://msdn.microsoft.com/en-us/library/bb608929.aspx will be helpful.

Sue Mosher

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

news:eqFpoVswJHA.6068@TK2MSFTNGP05.phx.gbl...

> "Sue Mosher [MVP]" <suemvp@turtleflock.com> schrieb im Newsbeitrag
> news:O3tMAyrwJHA.4592@TK2MSFTNGP06.phx.gbl...
> > You should be able to use ItemProperties.Item("UID") or
> > UserProperties.Item("UID").


> Thanks Sue that was the right hint to point me to a direction.
> My code looks now like this, I guess the above only works for
> VB.NET?

> Regards

> Michael (I got your Book allready ;))!

> codesnipet:
> ###########################################

> mail = (Outlook.MailItem)this.OutlookItem;
> this._txt1.Text = "Read:" + mail.Subject;
> try
> {
> this._txt2.Text = mail.ItemProperties["UID"].Value.ToString();
> }
> catch
> {
> this._txt2.Text = "???";
> }

>
 
K

Ken Slovak - [MVP - Outlook]

This C# code:

mail.ItemProperties["UID"] or mail.UserProperties["UID"]

is the equivalent of the VB type code:

mail.UserProperties.Item("UID") or mail.ItemProperties.Item("UID")

"Sue Mosher [MVP]" <suemvp@turtleflock.com> wrote in message

news:ekUZIvtwJHA.956@TK2MSFTNGP03.phx.gbl...
> I have no idea. I write code only for VB languages. Your best reference is
> the PIA documentation on MSDN; perhaps the example at
> http://msdn.microsoft.com/en-us/library/bb608929.aspx will be helpful.

> > Sue Mosher
> > >

> "Michael Schmitz" <spam@gmx.net> wrote in message
> news:eqFpoVswJHA.6068@TK2MSFTNGP05.phx.gbl...
>

>> "Sue Mosher [MVP]" <suemvp@turtleflock.com> schrieb im Newsbeitrag
> > news:O3tMAyrwJHA.4592@TK2MSFTNGP06.phx.gbl...
> >> You should be able to use ItemProperties.Item("UID") or
> >> UserProperties.Item("UID").

>

>> Thanks Sue that was the right hint to point me to a direction.
> > My code looks now like this, I guess the above only works for
> > VB.NET?
>

>> Regards
>

>> Michael (I got your Book allready ;))!
>

>> codesnipet:
> > ###########################################
>

>> mail = (Outlook.MailItem)this.OutlookItem;
> > this._txt1.Text = "Read:" + mail.Subject;
> > try
> > {
> > this._txt2.Text = mail.ItemProperties["UID"].Value.ToString();
> > }
> > catch
> > {
> > this._txt2.Text = "???";
> > }
>

>
>>


>
 
M

Michael Schmitz

" - " <kenslovak@mvps.org> schrieb im Newsbeitrag

news:%23vrL9y0wJHA.5836@TK2MSFTNGP06.phx.gbl...
> This C# code:

> mail.ItemProperties["UID"] or mail.UserProperties["UID"]

> is the equivalent of the VB type code:

> mail.UserProperties.Item("UID") or mail.ItemProperties.Item("UID")
>


Thanks, thats what i thought ;)
 
Status
Not open for further replies.
Top