【问题标题】:Drag and drop from an email file attachment in GroupWise to a .NET application从 GroupWise 中的电子邮件文件附件拖放到 .NET 应用程序
【发布时间】:2010-10-28 03:03:33
【问题描述】:

我正在尝试允许将在 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 合作的可怜人。

标签: .net winforms drag-and-drop groupwise


【解决方案1】:

我也没有运气找到这个。这是我想出的(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);
}

【讨论】:

  • 哇,谢谢约翰。这很酷,也有点奇怪:-)你是对的,只需访问 e.Data.GetData("attachment format") (不确定它是否甚至需要 ,true)创建文件。不知何故,我认为这是返回 null ,但我一定很困惑。再次感谢。干杯罗斯
  • 不幸的是,它对我不起作用 - GetData 返回 null。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多