4

我正在尝试允许将 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 桌面或其他文件夹中。

感谢您的任何建议。

4

1 回答 1

2

我也没有运气找到这个。这是我想出的(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);
}
于 2009-05-28T23:59:00.820 回答