我试图允许将Novell GroupWise中打开的电子邮件中的附件放入我的C#WinForms应用程序中.标准的.NET功能不起作用.
在控件的DragDrop事件中,e.Data.GetFormats()返回以下内容.
FileGroupDescriptorW
FileGroupDescriptor
FileContents
attachment format
我可以使用e.Data.GetData(“FileGroupDescriptor”)获取文件名并转到位置76.
不幸的是,e.Data.GetData(“FileContents”)在System.Windows.Forms.dll中导致第一次机会System.NotImplementedException并返回null.附件格式也返回null.
我的搜索告诉我,拖放比我想象的要复杂得多:)似乎GroupWise可能正在使用一种名为CFSTR_FILECONTENTS的格式,但这只是猜测.可以将附件成功拖放到Windows桌面或其他文件夹中.
谢谢你的任何建议.
最佳答案 我也没有找到这个运气.这是我想出的(Groupwise 7):
private void control_DragDrop(object sender, DragEventArgs e)
{
string strFilename = null;
//something about the act of reading this stream creates the file in your temp folder(?)
using (MemoryStream stream = (MemoryStream)e.Data.GetData("attachment format", true))
{
byte[] b = new byte[stream.Length];
stream.Read(b, 0, (int)stream.Length);
strFilename = Encoding.Unicode.GetString(b);
//The path/filename is at position 10.
strFilename = strFilename.Substring(10, strFilename.IndexOf('\0', 10) - 10);
stream.Close();
}
if (strFilename != null && File.Exists(strFilename))
{
//From here on out, you're just reading another file from the disk...
using(FileStream fileIn = File.Open(strFilename, FileMode.Open))
{
//Do your thing
fileIn.Close();
}
}
File.Delete(strFilename);
}