代码之家  ›  专栏  ›  技术社区  ›  tetranz

从GroupWise中的电子邮件文件附件拖放到.NET应用程序

  •  4
  • tetranz  · 技术社区  · 17 年前

    我试图允许将Novell GroupWise中打开的电子邮件的附件放到我的C_WinForms应用程序中。标准的.NET功能不起作用。

    在控件的dragDrop事件中,e.data.getFormats()返回以下内容。

    FileGroupDescriptorW
    FileGroupDescriptor
    FileContents
    attachment format
    

    我可以使用e.data.get data(“filegroupdescriptor”)获取文件名,并转到位置76。

    不幸的是,e.data.getdata(“filecontents”)导致System.Windows.Forms.dll中的第一次System.NotImplementedException,并返回空值。附件格式也返回空值。

    我的搜索告诉我拖放比我想象的要复杂得多:)看起来GroupWise可能使用了一种叫做cfstr_fileContents的格式,但这只是一个猜测。可以成功地将附件拖放到Windows桌面或其他文件夹中。

    谢谢你的建议。

    1 回复  |  直到 16 年前
        1
  •  2
  •   Joh    17 年前

    我也没找到这个。以下是我的想法(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);
    }
    
    推荐文章