我正在创建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
?
任何帮助将不胜感激。