Solved

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

Posted on 2008-06-10
3
297 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
  • 2
3 Comments
 
LVL 7

Expert Comment

by:AUmidh
Comment Utility
0
 
LVL 11

Author Comment

by:joekendall
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now