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
Solved

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

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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 …
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 …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
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 …

860 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