Domanda

Sto cercando di permettere un allegato da un messaggio di posta aperto a Novell GroupWise di essere lasciati nella mia applicazione C # WinForms. La funzionalità standard .NET non funziona.

In caso DragDrop di un controllo, e.Data.GetFormats () restituisce il seguente.

FileGroupDescriptorW
FileGroupDescriptor
FileContents
attachment format

posso ottenere il nome del file con e.Data.GetData ( "FileGroupDescriptor") e andando a posizionare 76.

Purtroppo, e.Data.GetData ( "FileContents") fa sì che un primo System.NotImplementedException chance in System.Windows.Forms.dll e restituisce null. formato allegato restituisce anche nullo.

Le mie ricerche mi dicono che il drag and drop è molto più complesso di quanto pensassi :) Sembra che GroupWise potrebbe utilizzare un formato chiamato CFSTR_FILECONTENTS ma questa è solo una supposizione. Gli attacchi possono essere trascinati e rilasciati con successo sul desktop di Windows o altre cartelle.

Grazie per eventuali suggerimenti.

È stato utile?

Soluzione

Non ho avuto fortuna trovare anche questo. Ecco cosa mi è venuta (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);
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top