COMException saving contact picture

B

Battistaar

Hi all, in my software i need to retrieve outlook contact picture, this is my
code to do that in c#:

private Image getOutlookPicture(Outlook.ContactItem contact)
{
Image img;
img = Properties.Resources.user; //default image
foreach (Outlook.Attachment at in contact.Attachments)
{
if (at.FileName == "ContactPicture.jpg" || at.FileName ==
"ContactPhoto")
{
string fullName ="temp.jpg";
at.SaveAsFile(fullName);
FileStream tempStream = new FileStream(fullName,
FileMode.Open);
img = Image.FromStream(tempStream);
tempStream.Close();
File.Delete(fullName);
}
}
return img;
}

all work fine when i find a ContactPhoto, with ContactPicture.jpg it throws
a COMException saying that it is unamble to save the attachment and
suggesting me to control folder's permission. I'm an amministrator user, and
with ContactPhoto file all work fine, so it's strange.
any idea?
and anyone knows why are some picture saved as ContactPicture.jpg and
someother as ContactPhoto?
 
D

Dmitry Streblechenko

Specify a fully qualified path name instead of just temp.jpg.
Chances are your current directory is one of the Program Files subfolder,
and normally users have no write access to that folder or any of its
subfolders.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
B

Battistaar

it doesn't work, i tried, and with ContactPhoto attachment it works with this
path
 
Top