I have this windows form app.. where i have a text box and from outlook i want to be able to drag and drop from outlook to the form and basically copy to this text box the subject and body text...
I thought i almost had this figured out.. here is the code near the end that tries to "find" the outlook (2007) window and find the mail item data:
Microsoft.Office.Interop.Outlook.Application outlook;
//outlook = (Microsoft.VisualBasic.Interaction.GetObject("", "Outlook.Application")) as Microsoft.Office.Interop.Outlook.Application;
try
{
//try to create comm component with vb interaction
outlook = (Microsoft.Office.Interop.Outlook.Application)Microsoft.VisualBasic.Interaction.GetObject("", "Outlook.Application");
}
catch (System.Exception ex)
{
throw new ApplicationException("error" + ex);
}
//get the active one
Microsoft.Office.Interop.Outlook.Explorer explorer = outlook.ActiveExplorer();
Microsoft.Office.Interop.Outlook.MailItem mail = (Microsoft.Office.Interop.Outlook.MailItem)explorer.Selection[0];
//if (mail.Subject = maildata("Betreff").ToString())
//{
return mail;
It gets stuck on the line
outlook = (Microsoft.Office.Interop.Outlook.Application)Microsoft.VisualBasic.Interaction.GetObject("", "Outlook.Application");
It will either sit there forever or if i actually put a break on the catch, i am shown "cannot create activex component" as an error...
I'm not sure how else to go about this.. any thoughts?
Thanks
JohnPosted May 7, 2008, 11:24 PM
Hi,
This is how I did it
First you need to make the AllowDrop = true;
then I use the following: for dragging and droping from outlook
Thanks John
private
void _DragEnter(object sender, DragEventArgs e){
e.Effect =
DragDropEffects.All;}
private void _DragDrop(object sender, DragEventArgs e){
Outlook.
ApplicationClass app = new Outlook.ApplicationClass();Outlook.
Selection sel = app.ActiveExplorer().Selection; foreach (object mitem in sel){
try{
Outlook.
ContactItem ci = (Outlook.ContactItem)mitem;ci.SaveAs(
Path.GetTempPath() + ci.FirstName + ".vcf", Outlook.OlSaveAsType.olVCard);}
catch{
try{
Outlook.
MailItem mi = (Outlook.MailItem)mitem;mi.SaveAs(
Path.GetTempPath() + mi.Subject.ToString() + ".msg", Outlook.OlSaveAsType.olMSG);}
catch
{ }
}
}
}