拖放在GroupWise的电子邮件文件附件.NET应用程序
-
23-08-2019 - |
题
我想允许从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);
}
不隶属于 StackOverflow