none
get Attachment PathName RRS feed

Answers

All replies

  • The attachment is stored inside the message, it is not located anywhere on the disk. You can use the SaveAsFile method of the Attachment class to save it as a file.

    What exactly are you looking for?

    Monday, July 6, 2015 1:09 PM
  • Attachment.PathName is only valid for the attachments with Attachment.Type = olByReference (4).

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, July 6, 2015 4:55 PM
  • According to the MSDN docs, the olByReference value is no longer supported since Microsoft Outlook 2007. The olByValue value is used by default to attach a copy of a file in the file system. So, I don't think it needs to be mentioned.
    Monday, July 6, 2015 5:00 PM
  • If you do not want to mention, don't mention it. The following script still works just fine in Outlook 2013

    set msg = Application.CreateItem(0)
    set attach = msg.Attachments.Add("c:\Temp\test.txt", olByReference)
    MsgBox attach.PathName
    msg.Save


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, July 6, 2015 8:32 PM
  • Well, great docs in MSDN! :)
    Tuesday, July 7, 2015 5:52 AM
  • Accrording to your description, Outlook.Attachment.PathName implies a disk location. The attachment is a file; if you want to interact with it, you have to treat it like a file, and that means saving it out to the local disk.The Outlook.Attachment object does not actually contain the attached file; it contains a link to the attached file, with some associated metadata.

    but you can try like below to get Attachment PathName:

    Outlook.MailItem mail = this.Application.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
    
    mail.Subject = "An attachment for you!";
    
    string attachment = "D:\\temp.txt";
    
    var attach = mail.Attachments.Add(attachment, Outlook.OlAttachmentType.olByReference);
    
    MessageBox.Show(attach.PathName);


    Tuesday, July 7, 2015 9:03 AM