Solved

How To Retrieve Data From Drag/Drop Of An Office Object

Posted on 2008-06-10
3
317 Views
Last Modified: 2008-06-20
I am using VB.NET 2008 to develop a windows form application. I would like to know how to capture an object such as a Report that is in Microsoft Access 2003 that is being dragged and dropped. When you drag and drop a Report from Microsoft Access to the Desktop, it creates a link. How do I capture the Report that is going to be dropped and put the link it will create into a ListView in my VB.NET form?

Thanks for your help in advance!

Joe
0
Comment
Question by:joekendall
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 7

Expert Comment

by:AUmidh
ID: 21756907
0
 
LVL 11

Author Comment

by:joekendall
ID: 21757020
I appreciate the links, but I have seen the same thing in other places. They just don't work for what I am doing. Here is my code in the DragDrop event of the ListView. It works fine if I have already made a link on the desktop and drag it over the ListView. It doesn't work though if I try to drag from Access over the ListView. Any help along those lines is appreciated. I thought there might be a way in the .NET framework without using an API. If I need to use an API, that will be fine as long as someone has some code I can use as a reference.

Private Sub lvObjects_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lvObjects.DragDrop
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            Dim MyFiles() As String
            Dim i As Integer
            ' Assign the files to an array.
            MyFiles = e.Data.GetData(DataFormats.FileDrop)

            ' Loop through the array and add the files to the list.
            For i = 0 To MyFiles.Length - 1
                lvResults.Items.Add(MyFiles(i))
            Next
        End If
    End Sub

Thanks!

Joe
0
 
LVL 11

Accepted Solution

by:
joekendall earned 0 total points
ID: 21769722
I figured it out. You can see the solution below:

Dim theStream As System.IO.MemoryStream = CType(e.Data.GetData("FileGroupDescriptor"), System.IO.MemoryStream)
        Dim fileGroupDescriptor() As Byte = New Byte(512) {}
        theStream.Read(fileGroupDescriptor, 0, 512)
        ' used to build the filename from the FileGroupDescriptor block
        Dim fileName As System.Text.StringBuilder = New System.Text.StringBuilder("")
        ' this trick gets the filename of the passed attached file
        Dim i As Integer = 76

        Do While fileGroupDescriptor(i) <> 0
            fileName.Append(Convert.ToChar(fileGroupDescriptor(i)))
            i += 1
        Loop

        theStream.Close()

        MsgBox(fileName.ToString)
        ' create the full-path name

        '
        ' Second step:  we have the file name.  
        ' Now we need to get the actual raw
        ' data for the attached file and copy it to disk so we work on it.
        '

        ' get the actual raw file into memory
        Dim ms As System.IO.MemoryStream = CType(e.Data.GetData("FileContents", True), System.IO.MemoryStream)
        Dim fileName2 As System.Text.StringBuilder = New System.Text.StringBuilder("")
        ' allocate enough bytes to hold the raw data
        Dim fileBytes() As Byte = New Byte(ms.Length) {}
        ' set starting position at first byte and read in the raw data
        ms.Position = 0
        ms.Read(fileBytes, 0, CType(ms.Length, Integer))
        i = 1
        Do While fileBytes(i) <> 0
            fileName2.Append(Convert.ToChar(fileBytes(i)))
            i += 1
        Loop

        ms.Close()

        MsgBox(fileName2.ToString)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

634 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question