我正在创建 Outlook add-in
,在其中创建拖放区域。
我想获取拖放到我控制中的邮件。我使用了以下代码:
private void DragDropControl_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");
//get the Mail Item here.
MemoryStream[] filestreams = (MemoryStream[])dataObject.GetData("FileContents");
this.label2.Text += "Files:\n";
for (int fileIndex = 0; fileIndex < filenames.Length; fileIndex++)
{
//use the fileindex to get the name and data stream
string filename = filenames[fileIndex];
MemoryStream filestream = filestreams[fileIndex];
this.label2.Text += " " + filename + "\n";
//save the file stream using its name to the application path
FileStream outputStream = File.Create(filename);
filestream.WriteTo(outputStream);
byte[] bytesInStream = new byte[outputStream.Length];
//I don't want to save file to the local drive or something like this.
var fileStream = File.Create("C:\\TestFileSave\\" + filename + ".msg");
outputStream.Seek(0, SeekOrigin.Begin);
outputStream.CopyTo(fileStream);
fileStream.Close();
outputStream.Close();
readMessage(filename);
}
}
在readMessage(filename)
函数中,我获取了保存的文件并读取了MailItem
.
但是当我在没有管理员权限的情况下运行 Outlook 时发生了实际问题,它给了我如下错误:
有没有其他方法可以在不将文件保存到本地驱动器的情况下将其转换为Outlook.MailItem
?
任何帮助将不胜感激。