Smart questions
Smart answers
Smart people
Join Tek-Tips Forums
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

groleau (Programmer) (OP)
5 Jun 07 14:08
I have to provide a way for a non-technical user to
add records to a database from a file.

The simplest method (for her, not for me!) would be
if she can drag the icon from the attachments panel of
GroupWise onto the desktop icon for my application.

I'd rather not use FileSystemWatcher, because that would
require it to be always running and tying up non-pageable
buffer space.on some machine.

But I'd also prefer to NOT tamper with the Registry
on her machine.

Ideas?  I found plenty about dragging/dropping things
within an application, but didn't spot anything
like this.

My fallback, I guess, would be for her to drag to a
directory, and have a scheduled task that empties
that directory frequently.

--
Wes Groleau
http://www.Parkview.com/

Borvik (Programmer)
5 Jun 07 15:11
This is very possible - in fact I use this myself for an administration program.  The salespeople run a simple program that sends me (via email) an xml file of the changes that they want to make.  I then drag the attachment directly to my program (from Outlook) to the label I set aside for drag-drop importing.

In my case it's a label (make sure to set the property AllowDrop to true).

Here is the code that enables it.  One routine is for allowing the drag-drop and showing the appropriate mouse over (handled by setting the e.Effect), the other is for processing the data.

CODE

    Private Sub lblImport_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lblImport.DragDrop
        If e.Effect = DragDropEffects.Copy And (e.Data.GetDataPresent(DataFormats.FileDrop) Or e.Data.GetDataPresent("FileContents")) Then
            Me.ParentForm.Activate()
            If e.Data.GetDataPresent(DataFormats.FileDrop) Then
                Dim strFiles() As String = e.Data.GetData(DataFormats.FileDrop)
                Dim strFile As String = strFiles(0)
                Dim ds As New DataSet
                Try
                    ds.ReadXml(strFile)
                Catch ex As Exception
                    MsgBox("Failed to read file properly.")
                    Exit Sub
                End Try
                ImportData(ds)
            Else
                Dim ms As IO.MemoryStream = e.Data.GetData("FileContents")
                Dim ds As New DataSet
                Try
                    ds.ReadXml(ms)
                Catch ex As Exception
                    MsgBox("Failed to read file properly.")
                End Try
                ms.Close()
                ImportData(ds)
            End If
        End If
    End Sub

    Private Sub lblImport_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lblImport.DragEnter
        e.Effect = DragDropEffects.None
        If e.Data.GetDataPresent(DataFormats.FileDrop) Or e.Data.GetDataPresent("FileGroupDescriptor") Then
            If e.Data.GetDataPresent(DataFormats.FileDrop) Then
                Dim files() As String = e.Data.GetData(DataFormats.FileDrop)
                If files.Length = 1 Then
                    Dim fi As New System.IO.FileInfo(files(0))
                    If fi.Extension.ToLower = ".xml" Then
                        e.Effect = DragDropEffects.Copy
                    End If
                End If
            Else
                Dim theStream As IO.MemoryStream = e.Data.GetData("FileGroupDescriptor")
                Dim fileGroupDescriptor() As Byte = theStream.ToArray()
                Dim fileName As New System.Text.StringBuilder
                Dim i As Integer = 76
                While fileGroupDescriptor(i) <> 0
                    fileName.Append(Convert.ToChar(fileGroupDescriptor(i)))
                    i += 1
                End While
                theStream.Close()
                Dim theFile As String = fileName.ToString
                Dim fi As New System.IO.FileInfo(theFile)
                If fi.Extension.ToLower = ".xml" Then
                    e.Effect = DragDropEffects.Copy
                End If
            End If
        End If
    End Sub

I'm not sure how it would work with GroupWise, but hopefully that helps you out.
groleau (Programmer) (OP)
5 Jun 07 16:40
Thanks, I'll consider that.

I'm a little leery of it for a non-savvy user, because
she would have to first launch the program, and then drag the attachment into the right spot..  

Not very difficult, true, but the more steps, the more chance of failure.

--
Wes Groleau
http://www.Parkview.com/

Mastakilla (Programmer)
5 Jun 07 16:53
Hi,

Take the solution Borvik proposed add the problem you expose stir it, shake it and you get a nice solution:

have your program launch when windows starts, let it reside in the system tray as a tray icon, let the user drag'n'drop the attached file on the icon, let your program handle the file the way Borvik proposed. Put a nice "Target" icon so the non savvy user can't miss it!


Best served chilled!
Cheers.

---
MASTAKILLA pipe

Borvik (Programmer)
5 Jun 07 16:58
I think I get what you mean.

Drag the email attachment directly to the shortcut to use as an argument for startup.

I just attempted to do the same thing, ie - I created a program that lists the command line args and then dragged (not a word I know) a file to it.  It did display the file path.  However, Windows didn't even allow the attachment to be dropped onto any executable.  It may not be possible to do it this way.

Based on what you want it to do - soley import data from files for this user.  To make it as simple as possible just make the entire form AllowDrop and apply the drag-and-drop code to that.  With the entire form drag-n-drop the least chance of failure with that specific scenario.
Borvik (Programmer)
5 Jun 07 16:59
On second thought - Mastakilla's solution is very nice too (compared to opening the program).
groleau (Programmer) (OP)
20 Jun 07 15:23
Thanks all!  I guess the "system tray target" is probably the easiest for non-technical users.  That would allow for later adding code to handle other file types--sort of a poor man's version of the Windows Registry.

And if the user dragged in a file that we hadn't coded for, we could pop up a nice "Sorry, our department doesn't handle files of that type--please contact ______ for support"

--
Wes Groleau
http://www.Parkview.com/

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close