Solved

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

Posted on 2008-06-10
3
309 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
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

735 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