Home All Groups Group Topic Archive Search About

How to access attachment property using CDO

Author
20 Mar 2009 11:46 AM
Ashish
For a contact item how to access PR_ATTACHMENT_CONTACTPHOTO property using
CDO or MAPI. I want to access this property on exchange server where outlook
is not installed. I tried with following
IBodyPart *part = message->Attachment->Item[1];
FieldsPtr flds = part->Fields;
Flds->GetItem(http://schemas.microsoft.com/mapi/proptag/0x7FFF000B);
But it returns no value.
Author
20 Mar 2009 2:41 PM
Ken Slovak - [MVP - Outlook]
CDO doesn't recognize DASL property tags, just use 0x7FFF000B for that. That
would also be how you'd get it using MAPI, the definition for it is listed
as:

#define PR_ATTACHMENT_CONTACTPHOTO PROP_TAG( PT_BOOLEAN, 0x7FFF).

Of course this only applies to contacts in Outlook 2007 and only where the
contact photo exists.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


Show quoteHide quote
"Ashish" <akohli_2***@hotmail.com> wrote in message
news:%237YoTIVqJHA.5332@TK2MSFTNGP03.phx.gbl...
> For a contact item how to access PR_ATTACHMENT_CONTACTPHOTO property using
> CDO or MAPI. I want to access this property on exchange server where
> outlook is not installed. I tried with following
> IBodyPart *part = message->Attachment->Item[1];
> FieldsPtr flds = part->Fields;
> Flds->GetItem(http://schemas.microsoft.com/mapi/proptag/0x7FFF000B);
> But it returns no value.
>
Are all your drivers up to date? click for free checkup

Author
21 Mar 2009 9:12 AM
Ashish
If i create a contact item. Insert one attachment(image file) using
Insert->File menu and add one picture by clicking on picture icon in contact
item. Then what's the difference between these two attachment. i mean which
property tells the difference in outlook 2003? And which property tells the
difference on exchange server.

Show quoteHide quote
"Ken Slovak - [MVP - Outlook]" <kenslo***@mvps.org> wrote in message
news:eD2xUtWqJHA.6132@TK2MSFTNGP06.phx.gbl...
> CDO doesn't recognize DASL property tags, just use 0x7FFF000B for that.
> That would also be how you'd get it using MAPI, the definition for it is
> listed as:
>
> #define PR_ATTACHMENT_CONTACTPHOTO PROP_TAG( PT_BOOLEAN, 0x7FFF).
>
> Of course this only applies to contacts in Outlook 2007 and only where the
> contact photo exists.
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007.
> Reminder Manager, Extended Reminders, Attachment Options.
> http://www.slovaktech.com/products.htm
>
>
> "Ashish" <akohli_2***@hotmail.com> wrote in message
> news:%237YoTIVqJHA.5332@TK2MSFTNGP03.phx.gbl...
>> For a contact item how to access PR_ATTACHMENT_CONTACTPHOTO property
>> using
>> CDO or MAPI. I want to access this property on exchange server where
>> outlook is not installed. I tried with following
>> IBodyPart *part = message->Attachment->Item[1];
>> FieldsPtr flds = part->Fields;
>> Flds->GetItem(http://schemas.microsoft.com/mapi/proptag/0x7FFF000B);
>> But it returns no value.
>>
>
Author
23 Mar 2009 12:52 PM
Ken Slovak - [MVP - Outlook]
Sorry, I mistyped. The property is there in both Outlook 2003 and 2007. If
the same image is added as an attachment and as a contact image the
difference is that the contact image attachment is named ContactPicture, and
the PR_ATTACHMENT_CONTACTPHOTO property is set to true. The other attachment
has that property set to false.

If there is only one attachment and it's not a contact image either the
PR_ATTACHMENT_CONTACTPHOTO property is set to false or won't be there.

In cases like this it's really helpful to use a MAPI viewer to see exactly
what's going on. MS has a free one you can download, MFCMAPI, and there's
another one from a 3rd party provider, OutlookSpy (www.dimastr.com) that can
be used.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


Show quoteHide quote
"Ashish" <akohli_2***@hotmail.com> wrote in message
news:u0$kJXgqJHA.3864@TK2MSFTNGP02.phx.gbl...
> If i create a contact item. Insert one attachment(image file) using
> Insert->File menu and add one picture by clicking on picture icon in
> contact item. Then what's the difference between these two attachment. i
> mean which property tells the difference in outlook 2003? And which
> property tells the difference on exchange server.
Author
23 Mar 2009 3:18 PM
Ashish
Thanks for this. But when i try to access PR_ATTACHMENT_CONTACTPHOTO, i dont
get any such property. I use following code

IBodyPart *part = message->Attachment->Item[1];
FieldsPtr flds = part->Fields;
Flds->GetItem(http://schemas.microsoft.com/mapi/proptag/0x7FFF000B);

Show quoteHide quote
"Ken Slovak - [MVP - Outlook]" <kenslo***@mvps.org> wrote in message
news:OtpjKZ7qJHA.5912@TK2MSFTNGP02.phx.gbl...
> Sorry, I mistyped. The property is there in both Outlook 2003 and 2007. If
> the same image is added as an attachment and as a contact image the
> difference is that the contact image attachment is named ContactPicture,
> and the PR_ATTACHMENT_CONTACTPHOTO property is set to true. The other
> attachment has that property set to false.
>
> If there is only one attachment and it's not a contact image either the
> PR_ATTACHMENT_CONTACTPHOTO property is set to false or won't be there.
>
> In cases like this it's really helpful to use a MAPI viewer to see exactly
> what's going on. MS has a free one you can download, MFCMAPI, and there's
> another one from a 3rd party provider, OutlookSpy (www.dimastr.com) that
> can be used.
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007.
> Reminder Manager, Extended Reminders, Attachment Options.
> http://www.slovaktech.com/products.htm
>
>
> "Ashish" <akohli_2***@hotmail.com> wrote in message
> news:u0$kJXgqJHA.3864@TK2MSFTNGP02.phx.gbl...
>> If i create a contact item. Insert one attachment(image file) using
>> Insert->File menu and add one picture by clicking on picture icon in
>> contact item. Then what's the difference between these two attachment. i
>> mean which property tells the difference in outlook 2003? And which
>> property tells the difference on exchange server.
>
Author
23 Mar 2009 8:28 PM
Ken Slovak - [MVP - Outlook]
I told you before you are accessing that property incorrectly using CDO
1.21. Just use the hex value of the property tag, CDO does not understand
DASL property tags. If you access it that way it will never work.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


Show quoteHide quote
"Ashish" <akohli_2***@hotmail.com> wrote in message
news:Ot5yqs8qJHA.5356@TK2MSFTNGP03.phx.gbl...
> Thanks for this. But when i try to access PR_ATTACHMENT_CONTACTPHOTO, i
> dont get any such property. I use following code
>
> IBodyPart *part = message->Attachment->Item[1];
> FieldsPtr flds = part->Fields;
> Flds->GetItem(http://schemas.microsoft.com/mapi/proptag/0x7FFF000B);
Author
24 Mar 2009 7:37 AM
Ashish
Thanks. I'm confused how to get this value. I'm using following code but i'm
getting empty value. please correct where i'm wrong

IBodyParts * MailAttachments;
HRESULT hr2 = pMsg->get_Attachments(&MailAttachments);
IBodyPartPtr atch = MailAttachments->GetItem(1);
FieldsPtr Flds = atch->Fields;
FieldPtr Fld;
hr = Fld = Flds->GetItem( "0x7FFF000B" );
VARIANT v = Fld->Value;

Show quoteHide quote
"Ken Slovak - [MVP - Outlook]" <kenslo***@mvps.org> wrote in message
news:exrnAY$qJHA.528@TK2MSFTNGP06.phx.gbl...
>I told you before you are accessing that property incorrectly using CDO
>1.21. Just use the hex value of the property tag, CDO does not understand
>DASL property tags. If you access it that way it will never work.
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007.
> Reminder Manager, Extended Reminders, Attachment Options.
> http://www.slovaktech.com/products.htm
>
>
> "Ashish" <akohli_2***@hotmail.com> wrote in message
> news:Ot5yqs8qJHA.5356@TK2MSFTNGP03.phx.gbl...
>> Thanks for this. But when i try to access PR_ATTACHMENT_CONTACTPHOTO, i
>> dont get any such property. I use following code
>>
>> IBodyPart *part = message->Attachment->Item[1];
>> FieldsPtr flds = part->Fields;
>> Flds->GetItem(http://schemas.microsoft.com/mapi/proptag/0x7FFF000B);
>
Author
24 Mar 2009 3:11 PM
Ken Slovak - [MVP - Outlook]
I don't know. Maybe Dan Mitchell will stop by and see this thread and
respond, he's a C++ CDO expert. I rarely do C++ coding.

The best suggestion I can think of is to post your question in the
microsoft.public.win32.programmer.messaging group, where Dan and some other
C++ people hang out, maybe someone there is familiar with this problem.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


Show quoteHide quote
"Ashish" <akohli_2***@hotmail.com> wrote in message
news:Oig7vPFrJHA.4364@TK2MSFTNGP04.phx.gbl...
> Thanks. I'm confused how to get this value. I'm using following code but
> i'm getting empty value. please correct where i'm wrong
>
> IBodyParts * MailAttachments;
> HRESULT hr2 = pMsg->get_Attachments(&MailAttachments);
> IBodyPartPtr atch = MailAttachments->GetItem(1);
> FieldsPtr Flds = atch->Fields;
> FieldPtr Fld;
> hr = Fld = Flds->GetItem( "0x7FFF000B" );
> VARIANT v = Fld->Value;
Author
24 Mar 2009 5:30 PM
Dan Mitchell
"Ken Slovak - [MVP - Outlook]" <kenslo***@mvps.org> wrote in
news:###vHLJrJHA.3584@TK2MSFTNGP05.phx.gbl:
> I don't know. Maybe Dan Mitchell will stop by and see this thread and
> respond, he's a C++ CDO expert. I rarely do C++ coding.

You rang?

> hr = Fld = Flds->GetItem( "0x7FFF000B" );

(without trying it) It looks like this line should be Flds->GetItem
(0x7FFF000B) -- possibly (long)0x7FFF000B, I forget right now.

You want to be passing in a number at this point, not a string with the
letters that you'd use to write that number down.

-- dan
Author
24 Mar 2009 7:40 PM
Ken Slovak - [MVP - Outlook]
Thanks, Dan, you're always reliable :)

I thought it should be a long and not a string value, but I was hazy about
that.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


Show quoteHide quote
"Dan Mitchell" <djmitche***@yahoo.com> wrote in message
news:Xns9BD87513341F5djmitchellayahoocom@127.0.0.1...
> "Ken Slovak - [MVP - Outlook]" <kenslo***@mvps.org> wrote in
> news:###vHLJrJHA.3584@TK2MSFTNGP05.phx.gbl:
>> I don't know. Maybe Dan Mitchell will stop by and see this thread and
>> respond, he's a C++ CDO expert. I rarely do C++ coding.
>
> You rang?
>
>> hr = Fld = Flds->GetItem( "0x7FFF000B" );
>
> (without trying it) It looks like this line should be Flds->GetItem
> (0x7FFF000B) -- possibly (long)0x7FFF000B, I forget right now.
>
> You want to be passing in a number at this point, not a string with the
> letters that you'd use to write that number down.
>
> -- dan
Author
25 Mar 2009 8:32 AM
Ashish
I tried with long value but it returns no value(control go to catch). After
this i check all values stored in fields with 2 mails. For first mail i
insert picture in contact photo and for second mail i insert it through
file->attachment and all fields values are same for both mails. There is no
single difference.

IBodyParts * MailAttachments = NULL;

HRESULT hr = pMsg->get_Attachments(&MailAttachments);

IBodyPartPtr part= MailAttachments ->GetItem(1);



FieldsPtr Flds;

FieldPtr Fld;

Flds = part->Fields;

long allitems = Flds->Count;

for(long k = 1; k <= allitems ; k++)

{

hr = Fld = Flds->GetItem(k);

if( SUCCEEDED( hr ) )

{

v = Fld->Value;

if( ( v.vt != VT_NULL ) && ( v.vt != VT_EMPTY ) )

{

VariantClear( &v );

}

}

}

Show quoteHide quote
"Dan Mitchell" <djmitche***@yahoo.com> wrote in message
news:Xns9BD87513341F5djmitchellayahoocom@127.0.0.1...
> "Ken Slovak - [MVP - Outlook]" <kenslo***@mvps.org> wrote in
> news:###vHLJrJHA.3584@TK2MSFTNGP05.phx.gbl:
>> I don't know. Maybe Dan Mitchell will stop by and see this thread and
>> respond, he's a C++ CDO expert. I rarely do C++ coding.
>
> You rang?
>
>> hr = Fld = Flds->GetItem( "0x7FFF000B" );
>
> (without trying it) It looks like this line should be Flds->GetItem
> (0x7FFF000B) -- possibly (long)0x7FFF000B, I forget right now.
>
> You want to be passing in a number at this point, not a string with the
> letters that you'd use to write that number down.
>
> -- dan
Author
25 Mar 2009 9:03 AM
SvenC
Hi Ashish,

Show quoteHide quote
> I tried with long value but it returns no value(control go to catch).
> After this i check all values stored in fields with 2 mails.

> IBodyParts * MailAttachments = NULL;
> HRESULT hr = pMsg->get_Attachments(&MailAttachments);
> IBodyPartPtr part= MailAttachments ->GetItem(1);
> FieldsPtr Flds;
> FieldPtr Fld;
> Flds = part->Fields;
> long allitems = Flds->Count;
> for(long k = 1; k <= allitems ; k++)
> {
> hr = Fld = Flds->GetItem(k);
>...

Which values do you get? Are you seeing any MAPI fields at all?
As I wrote in my other post, you are using CDOSYS which is not
MAPI based but SMTP based.
I guess you are confusing CDOSYS with CDO 1.21

--
SvenC
Author
25 Mar 2009 1:25 PM
Ashish
Yes i'm confuse now. I dont have much knowledge on CDO and MAPI.
If i create a contact item and attach one contact photo then i want to
access PR_ATTACHMENT_CONTACTPHOTO  on exchange server. What i should use now
mapi/cdo to access this property.
Please give a sample to access it.
Show quoteHide quote
"SvenC" <SvenC@nospam.nospam> wrote in message
news:umrWgiSrJHA.724@TK2MSFTNGP03.phx.gbl...
> Hi Ashish,
>
>> I tried with long value but it returns no value(control go to catch).
>> After this i check all values stored in fields with 2 mails.
>
>> IBodyParts * MailAttachments = NULL;
>> HRESULT hr = pMsg->get_Attachments(&MailAttachments);
>> IBodyPartPtr part= MailAttachments ->GetItem(1);
>> FieldsPtr Flds;
>> FieldPtr Fld;
>> Flds = part->Fields;
>> long allitems = Flds->Count;
>> for(long k = 1; k <= allitems ; k++)
>> {
>> hr = Fld = Flds->GetItem(k);
>>...
>
> Which values do you get? Are you seeing any MAPI fields at all?
> As I wrote in my other post, you are using CDOSYS which is not
> MAPI based but SMTP based.
> I guess you are confusing CDOSYS with CDO 1.21
>
> --
> SvenC
Author
25 Mar 2009 2:47 PM
Ken Slovak - [MVP - Outlook]
I'd suggest, as I did before, getting a MAPI viewer. You can use OutlookSpy
from www.dimastr.com or the MFCMAPI viewer that's available as a free
download from MS. Look at both attachments in the attachment table of the
item and take a look at the properties on each attachment.

The attachment added as a contact photo should have
PR_ATTACHMENT_CONTACTPHOTO set to true. The other attachment should have
that property set to false.

If the property is not there on either attachment then something else is
wrong. But it would explain why you aren't getting a value from that
property.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


Show quoteHide quote
"Ashish" <akohli_2***@hotmail.com> wrote in message
news:OTnhY3UrJHA.1236@TK2MSFTNGP02.phx.gbl...
> Yes i'm confuse now. I dont have much knowledge on CDO and MAPI.
> If i create a contact item and attach one contact photo then i want to
> access PR_ATTACHMENT_CONTACTPHOTO  on exchange server. What i should use
> now mapi/cdo to access this property.
> Please give a sample to access it.
> "SvenC" <SvenC@nospam.nospam> wrote in message
> news:umrWgiSrJHA.724@TK2MSFTNGP03.phx.gbl...
>> Hi Ashish,
>>
>>> I tried with long value but it returns no value(control go to catch).
>>> After this i check all values stored in fields with 2 mails.
>>
>>> IBodyParts * MailAttachments = NULL;
>>> HRESULT hr = pMsg->get_Attachments(&MailAttachments);
>>> IBodyPartPtr part= MailAttachments ->GetItem(1);
>>> FieldsPtr Flds;
>>> FieldPtr Fld;
>>> Flds = part->Fields;
>>> long allitems = Flds->Count;
>>> for(long k = 1; k <= allitems ; k++)
>>> {
>>> hr = Fld = Flds->GetItem(k);
>>>...
>>
>> Which values do you get? Are you seeing any MAPI fields at all?
>> As I wrote in my other post, you are using CDOSYS which is not
>> MAPI based but SMTP based.
>> I guess you are confusing CDOSYS with CDO 1.21
>>
>> --
>> SvenC
>
>
Author
26 Mar 2009 8:43 AM
SvenC
Hi Ashish,

> Yes i'm confuse now. I dont have much knowledge on CDO and MAPI.

Download MFCMAPI binary and source code from here:

http://www.codeplex.com/MFCMAPI

This should help you to learn and understand MAPI programming.

--
SvenC
Author
24 Mar 2009 7:22 PM
SvenC
Hi Ashish,

> For a contact item how to access PR_ATTACHMENT_CONTACTPHOTO property using
> CDO or MAPI. I want to access this property on exchange server where
> outlook is not installed. I tried with following
> IBodyPart *part = message->Attachment->Item[1];
> FieldsPtr flds = part->Fields;
> Flds->GetItem(http://schemas.microsoft.com/mapi/proptag/0x7FFF000B);
> But it returns no value.

You are usind CDOSYS which is not related to MAPI.

You must use CDO 1.21 or directly extended MAPI

CDO 1.21 does also have a Fields collection which you seem to confuse
with ADODB::Fields.
http://msdn.microsoft.com/en-us/library/ms527269(EXCHG.10).aspx

In ExMAPI you use IMAPIProps::GetProps.

--
SvenC

Bookmark and Share