【发布时间】:2013-11-16 05:00:57
【问题描述】:
我正在为 Outlook 创建加载项。我在其中创建了拖放用户控件。
当我拖放邮件时,会提取一些邮件并提供适当的信息,但在收件箱中的某些邮件中,会出现类似错误:
我正在使用以下代码来获取被拖动邮件的信息:
private void DragNDropArea_DragDrop(object sender, DragEventArgs e)
{
//wrap standard IDataObject in OutlookDataObject
OutlookDataObject dataObject = new OutlookDataObject(e.Data);
//get the names and data streams of the files dropped
string[] filenames = (string[])dataObject.GetData("FileGroupDescriptorW");
MemoryStream[] filestreams = (MemoryStream[])dataObject.GetData("FileContents");
this.label2.Text += "Files:\n";
for (int fileIndex = 0; fileIndex < filenames.Length; fileIndex++)
{
try
{
//use the fileindex to get the name and data stream
string filename = filenames[fileIndex];
MemoryStream filestream = filestreams[fileIndex];
this.label2.Text += " " + filename + "\n";
Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
Outlook._NameSpace nameSpace = app.GetNamespace("MAPI");
nameSpace.Logon(null, null, false, false);
Outlook.Folder folder = (Outlook.Folder)app.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
//From this it gives me mentioned error...
Outlook.MailItem msg = (Outlook.MailItem)app.CreateItemFromTemplate(filename, folder);
string sender1 = msg.SenderEmailAddress;
MessageBox.Show("Sender: \n" + msg.Sender.Name + "\n" + msg.Sender.Address);
MessageBox.Show("Message Body: \n" + msg.Body);
MessageBox.Show("Total Attachments: " + msg.Attachments.Count);
for (int i = 1; i <= msg.Attachments.Count; i++)
{
MessageBox.Show("Attachment " + i + " :" + msg.Attachments[i].FileName);
msg.Attachments[i].SaveAsFile("C:\\TestFileSave\\" + msg.Attachments[i].FileName);
}
}
catch (System.Exception ex)
{
MessageBox.Show("Error Occured In getting Mail info..: \n" + ex.ToString());
}
}
}
当我从我在收件箱文件夹中创建的文件夹中拖动邮件时,对于每个被拖动的邮件,都会出现相同的错误。
我该如何解决这个问题?
【问题讨论】:
标签: c# drag-and-drop outlook outlook-addin