How to Cast a dropped Outlook Contact Item on a Winform C#?
使用拖放的方法DragDrop
this.textBox.DragDrop += new System.Windows.Forms.DragEventHandler(this.textBox3_DragDrop);
this.textBox.DragEnter += new System.Windows.Forms.DragEventHandler(this.textBox3_DragEnter);
private void textBox_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Link; //鼠标的样式
}
private void textBox_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetFormats()[0] == "RenPrivateSourceFolder")
{
Microsoft.Office.Interop.Outlook.Application outlook = Marshal.GetActiveObject("Outlook.Application") as Microsoft.Office.Interop.Outlook.Application;
Microsoft.Office.Interop.Outlook.MailItem contact = outlook.ActiveExplorer().Selection[1] as Microsoft.Office.Interop.Outlook.MailItem;
if (contact != null)
{
//string title = contact.Subject.Replace(":","_").Replace("//","_").Replace("/","_").Replace("*","_").Replace("?","_").Replace("<","_").Replace(">","_").Replace("|","_").Replace("/"","_");
string title = Regex.Replace(contact.Subject, @"[/////:/?/</>/*/|///""]", "_");
//文件夹以当天时间命名,如20090421
string strDate = DateTime.Now.Date.ToString("yyyyMM");
string strHM = DateTime.Now.ToString("yyyyMMddHHmmssfff");
//string priPath = @"//qcsap/its8686_send/";
string priPath = System.Configuration.ConfigurationSettings.AppSettings["strPath"];
if (!Directory.Exists(priPath+strDate))//判断文件夹是否存在
{
Directory.CreateDirectory(priPath + strDate); //创建新文件夹
}
contact.SaveAs(priPath+strDate+"//"+strHM+"_"+title + ".msg", Type.Missing);
textBox.Text = priPath + strDate + "//" +strHM+"_"+title + ".msg";
}
else
{
MessageBox.Show("Not Contact Item");
}
}
else
{
MessageBox.Show("Not Outlook Item");
}
}