Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-06-10
3
Medium Priority
?
324 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
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 …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

688 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