Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

drag & drop attachment from outlook 1

SoftArt

Programmer
Feb 22, 2007
31
DE
Hi Foxis,

I am familiar with drag & drop of files from explorer, but i need help with drag & drop of outlook attachments (pdf)
Does anyone have an example code for this?

Thomas
 
You are wanting to drag an attachment in Outlook to a VFP app, get a reference to it, and process it in VFP in some fashion?
 
Yes, the file (pdf) should then be copied/created in VFP app to a specific directory.
 
Tamar,

in found a little bug in your code:

oObjColl = ThisForm.oOutlook.oExplorer.Selection must be
oObjColl = ThisForm..oExplorer.Selection

after that modification I got the attachement object and it´s SaveAsFile method.
Many thanks you for help und greetings from Germany.

Thomas
 
Glad I was able to help.

I guess you found the code. For others, the downloads for each session on my site are linked at http://tomorrowssolutionsllc.com/conferencepapers.php.

Tamar
Tamar,

I rejoiced a little too soon.
With your code I get information on all the attachments contained in the mail, but not the currently selected.
I have experimented a bit with AttachmentSelection but I can't get any further. Do you have another idea for me?

Thomas
 
Last edited:
Not something I've played with, but AttachmentSelection looks like it should get you what you need. Maybe show us some code.

Tamar
 
Tamar,

with this example all attachments are read out and saved/displayed. (TextBox.OLEDragDrop)
I don't know where I would have to use AttachmentSelection.

Thomas


* Create Outlook Application object
oOutlook = CREATEOBJECT("Outlook.Application")
oNamespace = oOutlook.GetNamespace("MAPI")

* Get the ActiveExplorer (the current open window in Outlook)
oExplorer = oOutlook.ActiveExplorer()

* Get the selected item (e.g., email)
oSelection = oExplorer.Selection
IF oSelection.Count > 0
* Get the first selected email (assuming only one item is selected)
oMail = oSelection.Item(1)

* Check if the email has attachments
IF oMail.Attachments.Count > 0
* Loop through the attachments collection
FOR i = 1 TO oMail.Attachments.Count
oAttachment = oMail.Attachments.Item(i)

* Save the attachment locally (e.g., save to C:\Temp\attachment.txt)
*oAttachment.SaveAsFile("C:\Temp\" + oAttachment.FileName)
? "Attachment saved as: " + "C:\Temp\" + oAttachment.FileName
NEXT
ELSE
? "No attachments found in the selected email."
ENDIF
ELSE
? "No email is selected."
ENDIF
 
I'd say it depends whether you drag&drop the mail item or drag an attachment in an opened mail. You can drag so many things, that it's quite impossible to write exhaustive code that covers all cases. Seems to me you found a way to cope with a mail item dragged into your VFP application and get all its attachments.

When you google "Outlook AttachmentSelection" you find that it is a collection of selected attachments, if you selected them, not necessarily dragged them. And I think dragging them also doesn't necessarily select them. So it would be a thing you could even react to without using drag&drop, as long as you got the Outlook object of the currently used session a user acts on. And to get events like a selection is done, I think you'd need to dig into writing an eventhandler. But it seems you found a simpler solution working with drag&drop of mail items.
 
Last edited:
Chris,

interesting idea, I want to try it.
But I would think that marked attachments for AttchmentSelection are also selected for drag & drop.

Thomas
 
So, my new solution works :)
Shortened code for selected attachments

loOutlook = CREATEOBJECT( "Outlook.Application" )
loSelected = loOutlook.ActiveInspector.AttachmentSelection
FOR i = 1 TO loSelected.Count
MESSAGEBOX( loSelected.Item(i).FileName )
* or loSelected.Item(i).SaveAsFile(...)
NEXT

Thomas
 

Part and Inventory Search

Sponsor

Back
Top