Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. How to drag-and-drop an .msg file from MS Outlook?

How to drag-and-drop an .msg file from MS Outlook?

Scheduled Pinned Locked Moved WPF
helpcsharpwpfperformancetutorial
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vipul Mehta
    wrote on last edited by
    #1

    Hi, In my WPF application I have a requirement where in user can drag-and-drop an email (.msg file) either from the file system OR MS Outlook. When user drags-and-drop the .msg file from the file system the file gets added. But when user drags-and-drop a .msg file from MS Outlook, it throws following exception Exception from HRESULT: 0x80040068 (DV_E_LINDEX I have implemented the below code & I encounter error on below line MemoryStream ms = (MemoryStream)e.Data.GetData("FileContents", true);

    string[] fileNames = null;

    if (e.Data.GetDataPresent(DataFormats.FileDrop, false))

    {

    fileNames = e.Data.GetData(DataFormats.FileDrop, true) as string[];

    foreach (string fileName in fileNames)

    {

    FileInfo fileInfo = new FileInfo(fileName);

    // Some logic goes here...

    }

    }

    else if (e.Data.GetDataPresent("FileGroupDescriptor"))

    {

    Stream theStream = (Stream)e.Data.GetData("FileGroupDescriptor");

    byte[] fileGroupDescriptor = new byte[512];

    theStream.Read(fileGroupDescriptor, 0, 512);

    StringBuilder fileName = new StringBuilder("");

    // Get the file name of the attached file

    for (int i = 76; fileGroupDescriptor[i] != 0; i++)

    {

    fileName.Append(Convert.ToChar(fileGroupDescriptor[i]));

    }

    theStream.Close();

    string path = Path.GetTempPath();

    string theFile = path + fileName.ToString();

    // Define full path for temp file

    // Get the raw file into memory

    MemoryStream ms = (MemoryStream)e.Data.GetData("FileContents", true);

    byte[] fileBytes = new byte[ms.Length];

    ms.Position = 0;

    ms.Read(fileBytes, 0, (int)ms.Length);

    FileStream fs = new FileStream(theFile, FileMode.Create);

    fs.Write(fileBytes, 0, (int)fileBytes.Length);

    fs.Close();

    // Get the FileInfo to use

    FileInfo tempFile = new FileInfo(theFile);

    // Verify the file was created

    if (tempFile.Exists)

    {

    // Some Logic goes here

    // Delete the temporary file once done with it

    tempFile.Delete();

    }

    What might be the issue here? Kindly help.

    Regards, Vipul Mehta

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups