473,385 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Drag/Drop/Upload Functionallity

Hello, I was wondering if there is a way that I can enable my
application to accept a file such as a .pdf that when dropped onto the
document, it will upload the file to my database or a directory.

I am trying to make the app as user friendly as possable and would
just like the users to be able to drop the file into an area of the
screen and it would just accept the document and maybe prompt if there
is an existing file for that record in the database.

Any help would be apperciated.

-Matt

Mar 20 '07 #1
10 2306
Assuming this is a windows application and that the problem is with
drag/drop handling, try :

http://www.vbforums.com/showthread.php?t=328593

---
Patrice
"Webbyz" <ma*******@gmail.coma écrit dans le message de news:
11**********************@e65g2000hsc.googlegroups. com...
Hello, I was wondering if there is a way that I can enable my
application to accept a file such as a .pdf that when dropped onto the
document, it will upload the file to my database or a directory.

I am trying to make the app as user friendly as possable and would
just like the users to be able to drop the file into an area of the
screen and it would just accept the document and maybe prompt if there
is an existing file for that record in the database.

Any help would be apperciated.

-Matt

Mar 20 '07 #2


It seems like the example shows just picture handeling. But this does
not have any way to absorb the file directly into a directory or Db.

Mar 20 '07 #3
Sorry, was not sure if the problem was also with those operations or if you
had already something but wanted to add drag/drop capability...

To copy a file just see the documentation for System.IO.File (or the My
namespaces if VB 2005).
For the BLOB part see the ADO.NET documentation :
http://msdn2.microsoft.com/en-us/library/4f5s1we0.aspx

---
Patrice

"Webbyz" <ma*******@gmail.coma écrit dans le message de news:
11**********************@o5g2000hsb.googlegroups.c om...
>

It seems like the example shows just picture handeling. But this does
not have any way to absorb the file directly into a directory or Db.

Mar 20 '07 #4
It seems like this function is hanging up where it wants to import the
data with the type Byte.

I keep getting the once I select the file to import and it attempts to
read into the Db. It just doesnt like the type Byte for some reason.

Any other ideas?

Mar 20 '07 #5
Doesn't like that is ? Do you have any error message ? What is the DB you
are using ? What is the size of the file you tried ?

---
Patrice
"Webbyz" <ma*******@gmail.coma écrit dans le message de news:
11**********************@o5g2000hsb.googlegroups.c om...
It seems like this function is hanging up where it wants to import the
data with the type Byte.

I keep getting the once I select the file to import and it attempts to
read into the Db. It just doesnt like the type Byte for some reason.

Any other ideas?

Mar 21 '07 #6
The size of the file is a .pdf which is about 750kb.

Error as follows.
"An error was thrown by the ADO.Net component in the GetData function.
Error Details: Syntax error (missing operator) in query expression
"System.Byte[]""

Database is a Access 2000 .mdb With three fields.
1.) ID - AutoNumber
2.) Description - Text
3.) File - OLEObject

Here is my code so far.

Imports System.IO
Public Class Form1

Public Shared Sub AddFile(ByVal pdfFilePath As String)

Dim newFile() As Byte = GetFile(pdfFilePath)

UpdateData("INSERT INTO Table1 (Description, File) VALUES('" &
My.Computer.FileSystem.GetFileInfo(pdfFilePath).Na me & "'," &
newFile.ToString & ")")

End Sub

Public Shared Function GetFile(ByVal filePath As String) As Byte()
Dim stream As FileStream = New FileStream( _
filePath, FileMode.Open, FileAccess.Read)
Dim reader As BinaryReader = New BinaryReader(stream)

Dim newFile() As Byte = reader.ReadBytes(stream.Length)

reader.Close()
stream.Close()

Return newFile
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim OFD As New OpenFileDialog
With OFD
.Title = "Select file..."
.Filter = "All Files (*.*)|*.*|PDF Documents (*.pdf)|
*.pdf"
.ShowHelp = False
.ShowReadOnly = False
.ShowDialog()
.Multiselect = False
If File.Exists(.FileName) Then
AddFile(.FileName)
Else
MsgBox("File not found!")
End If
End With
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button2.Click
Dim myDataset As DataSet
' Grab all records in this table with ID 1 or whatever number
you want
myDataset = GetData("SELECT * FROM [table1] WHERE [ID]=1",
"myFile")
If myDataset.Tables("myFile").Rows.Count 0 Then ' found the
File
Label1.Text =
myDataset.Tables("myFile").Rows(0).Item("Descripti on").ToString
' Get a temp file form windows
Dim TempFileName As String =
My.Computer.FileSystem.GetTempFileName
' get the file data and put it into a file or something
Label2.Text =
myDataset.Tables("myFile").Rows(0).Item("File").To String
Else
MsgBox("No record found!")
End If
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

End Sub
End Class

Mar 21 '07 #7
And what does GetData ? Are you using option strict ? It would seem you use
a byte at an inappropriate place.

The simplest sample I could come with is :
Dim Connection As New OleDbConnection(ConnectionString)
Dim Command As New OleDbCommand("SELECT TOP 1 Blob FROM Table1",
Connection)
Connection.Open()
Dim Reader As OleDb.OleDbDataReader =
Command.ExecuteReader(CommandBehavior.SequentialAc cess)
Reader.Read()
Dim Blob(255) As Byte
Reader.GetBytes(0, 0, Blob, 0, 255)
Reader.Close()
Command.Dispose()
Connection.Close()
For i As Integer = 0 To UBound(Blob)
If Blob(i) <i Then MsgBox("Doesn't match")
Debug.Print(i & "/" & Blob(i))
Next

The final check just allows to see that data are retrieved correctly (I
stored a small buffer with value n at the nth position).

Finally it's likely better to retrieve regular data using a query and to
handle blob data with another query so that you don't incurs the overhead of
processing potentially huge values when this is not really needed...

---
Patrice

"Webbyz" <ma*******@gmail.coma écrit dans le message de news:
11**********************@o5g2000hsb.googlegroups.c om...
The size of the file is a .pdf which is about 750kb.

Error as follows.
"An error was thrown by the ADO.Net component in the GetData function.
Error Details: Syntax error (missing operator) in query expression
"System.Byte[]""

Database is a Access 2000 .mdb With three fields.
1.) ID - AutoNumber
2.) Description - Text
3.) File - OLEObject

Here is my code so far.

Imports System.IO
Public Class Form1

Public Shared Sub AddFile(ByVal pdfFilePath As String)

Dim newFile() As Byte = GetFile(pdfFilePath)

UpdateData("INSERT INTO Table1 (Description, File) VALUES('" &
My.Computer.FileSystem.GetFileInfo(pdfFilePath).Na me & "'," &
newFile.ToString & ")")

End Sub

Public Shared Function GetFile(ByVal filePath As String) As Byte()
Dim stream As FileStream = New FileStream( _
filePath, FileMode.Open, FileAccess.Read)
Dim reader As BinaryReader = New BinaryReader(stream)

Dim newFile() As Byte = reader.ReadBytes(stream.Length)

reader.Close()
stream.Close()

Return newFile
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim OFD As New OpenFileDialog
With OFD
.Title = "Select file..."
.Filter = "All Files (*.*)|*.*|PDF Documents (*.pdf)|
*.pdf"
.ShowHelp = False
.ShowReadOnly = False
.ShowDialog()
.Multiselect = False
If File.Exists(.FileName) Then
AddFile(.FileName)
Else
MsgBox("File not found!")
End If
End With
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button2.Click
Dim myDataset As DataSet
' Grab all records in this table with ID 1 or whatever number
you want
myDataset = GetData("SELECT * FROM [table1] WHERE [ID]=1",
"myFile")
If myDataset.Tables("myFile").Rows.Count 0 Then ' found the
File
Label1.Text =
myDataset.Tables("myFile").Rows(0).Item("Descripti on").ToString
' Get a temp file form windows
Dim TempFileName As String =
My.Computer.FileSystem.GetTempFileName
' get the file data and put it into a file or something
Label2.Text =
myDataset.Tables("myFile").Rows(0).Item("File").To String
Else
MsgBox("No record found!")
End If
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

End Sub
End Class

Mar 21 '07 #8
Well at this point the GetData is gathering the Data and passing it
into the Db.

Here is the Module for that function.
Module DataAccessModule
Friend Function GetData(ByVal strSQL As String, ByVal TableName As
String) As DataSet
Dim myDataset As DataSet = New DataSet
' Create our connection string
Dim myConnString As OleDbConnection = New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:
\db1.mdb")
' Create our command
Dim myCommand As OleDbCommand = New OleDbCommand(strSQL,
myConnString)
' Create our data adapter
Dim myDataAdapter As OleDbDataAdapter = New OleDbDataAdapter
' Assign the SQL command to the data adapter
myDataAdapter.SelectCommand = myCommand
Try
' Fill the dataset with the data from our command
myDataAdapter.Fill(myDataset, TableName)
' Return the dataset
GetData = myDataset
Catch ex As OleDbException
MsgBox("An error was thrown by the ADO.Net component in
the GetData function. Error Details: " & _
vbCr & ex.Message, MsgBoxStyle.Exclamation, "Error!")
Debug.WriteLine("SQL Statement: " & strSQL)
GetData = Nothing
Finally
' Close the connection and destroy our connection objects
myCommand.Connection.Close()
myDataset = Nothing
myConnString = Nothing
myCommand = Nothing
myDataAdapter = Nothing
End Try
End Function

Friend Function UpdateData(ByVal strSQL As String) As Integer
' Create our connection string
Dim myConnString As OleDbConnection = New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:
\db1.mdb")
' Create our command
Dim myCommand As OleDbCommand = New OleDbCommand(strSQL,
myConnString)
Try
' Open the connection
myCommand.Connection.Open()
' execute the SQL
UpdateData = myCommand.ExecuteNonQuery()
Catch ex As OleDbException
MsgBox("An error was thrown by the ADO.Net component in
the GetData function. Error Details: " & _
vbCr & ex.Message, MsgBoxStyle.Exclamation, "Error!")
Debug.WriteLine("SQL Statement: " & strSQL)
UpdateData = Nothing
Finally
' Close the connection and destroy our connection object
myCommand.Connection.Close()
myConnString = Nothing
myCommand = Nothing
End Try
End Function

End Module

Mar 21 '07 #9
Ok the error message is actually misleading as the method name is not
correct. This is actually in the insertion statement where you use to string
that dumps the type name inside the SQL statement resulting in a SQL syntax
error...

Please post a message if you solve the problem. I'll try to post a sample
later today so that you can go back on better tracks...
----
Patrice

"Webbyz" <ma*******@gmail.coma écrit dans le message de news:
11**********************@d57g2000hsg.googlegroups. com...
Well at this point the GetData is gathering the Data and passing it
into the Db.

Here is the Module for that function.
Module DataAccessModule
Friend Function GetData(ByVal strSQL As String, ByVal TableName As
String) As DataSet
Dim myDataset As DataSet = New DataSet
' Create our connection string
Dim myConnString As OleDbConnection = New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:
\db1.mdb")
' Create our command
Dim myCommand As OleDbCommand = New OleDbCommand(strSQL,
myConnString)
' Create our data adapter
Dim myDataAdapter As OleDbDataAdapter = New OleDbDataAdapter
' Assign the SQL command to the data adapter
myDataAdapter.SelectCommand = myCommand
Try
' Fill the dataset with the data from our command
myDataAdapter.Fill(myDataset, TableName)
' Return the dataset
GetData = myDataset
Catch ex As OleDbException
MsgBox("An error was thrown by the ADO.Net component in
the GetData function. Error Details: " & _
vbCr & ex.Message, MsgBoxStyle.Exclamation, "Error!")
Debug.WriteLine("SQL Statement: " & strSQL)
GetData = Nothing
Finally
' Close the connection and destroy our connection objects
myCommand.Connection.Close()
myDataset = Nothing
myConnString = Nothing
myCommand = Nothing
myDataAdapter = Nothing
End Try
End Function

Friend Function UpdateData(ByVal strSQL As String) As Integer
' Create our connection string
Dim myConnString As OleDbConnection = New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:
\db1.mdb")
' Create our command
Dim myCommand As OleDbCommand = New OleDbCommand(strSQL,
myConnString)
Try
' Open the connection
myCommand.Connection.Open()
' execute the SQL
UpdateData = myCommand.ExecuteNonQuery()
Catch ex As OleDbException
MsgBox("An error was thrown by the ADO.Net component in
the GetData function. Error Details: " & _
vbCr & ex.Message, MsgBoxStyle.Exclamation, "Error!")
Debug.WriteLine("SQL Statement: " & strSQL)
UpdateData = Nothing
Finally
' Close the connection and destroy our connection object
myCommand.Connection.Close()
myConnString = Nothing
myCommand = Nothing
End Try
End Function

End Module

Mar 22 '07 #10
Ok so I made oledb samples from the SQLClient samples I discussed earlier in
the thread. It would give us for writing :

Dim BlobIn(255) As Byte
For i As Integer = 0 To UBound(BlobIn)
BlobIn(i) = CByte(i Mod 255)
Next
Dim Connection As New OleDbConnection(ConnectionString)
Dim Command As New OleDbCommand("INSERT INTO Table1(Blob) VALUES
(?)", Connection)
Connection.Open()
Command.Parameters.Add("a", OleDbType.Binary, UBound(BlobIn)).Value
= BlobIn
Command.ExecuteNonQuery()
For reading :
Dim BlobOut(1024) As Byte
Command = New OleDbCommand("SELECT TOP 1 Blob FROM Table1",
Connection) ' Would select using the PK
Dim Reader As OleDbDataReader = Command.ExecuteReader
Reader.Read()

Debug.Print(Reader.GetBytes(0, 0, BlobOut, 0,
BlobOut.Length).ToString) ' Could stream the result in chunks to a file
For i As Integer = 0 To UBound(BlobIn)
If BlobIn(i) <BlobOut(i) Then MsgBox("Mismatch !")
Next
Connection.Close()

Assuming you have a Table1 table with a Blob field and no records. It alos
test that the fictionous writren blob is the same than the blob we read back
later. From there you should have a starting point allowing to do what you
want...

---

Patrice
"Patrice" <http://www.chez.com/scribe/a écrit dans le message de news:
eT**************@TK2MSFTNGP03.phx.gbl...
Ok the error message is actually misleading as the method name is not
correct. This is actually in the insertion statement where you use to
string that dumps the type name inside the SQL statement resulting in a
SQL syntax error...

Please post a message if you solve the problem. I'll try to post a sample
later today so that you can go back on better tracks...
----
Patrice

"Webbyz" <ma*******@gmail.coma écrit dans le message de news:
11**********************@d57g2000hsg.googlegroups. com...
>Well at this point the GetData is gathering the Data and passing it
into the Db.

Here is the Module for that function.
Module DataAccessModule
Friend Function GetData(ByVal strSQL As String, ByVal TableName As
String) As DataSet
Dim myDataset As DataSet = New DataSet
' Create our connection string
Dim myConnString As OleDbConnection = New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=c:
\db1.mdb")
' Create our command
Dim myCommand As OleDbCommand = New OleDbCommand(strSQL,
myConnString)
' Create our data adapter
Dim myDataAdapter As OleDbDataAdapter = New OleDbDataAdapter
' Assign the SQL command to the data adapter
myDataAdapter.SelectCommand = myCommand
Try
' Fill the dataset with the data from our command
myDataAdapter.Fill(myDataset, TableName)
' Return the dataset
GetData = myDataset
Catch ex As OleDbException
MsgBox("An error was thrown by the ADO.Net component in
the GetData function. Error Details: " & _
vbCr & ex.Message, MsgBoxStyle.Exclamation, "Error!")
Debug.WriteLine("SQL Statement: " & strSQL)
GetData = Nothing
Finally
' Close the connection and destroy our connection objects
myCommand.Connection.Close()
myDataset = Nothing
myConnString = Nothing
myCommand = Nothing
myDataAdapter = Nothing
End Try
End Function

Friend Function UpdateData(ByVal strSQL As String) As Integer
' Create our connection string
Dim myConnString As OleDbConnection = New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=c:
\db1.mdb")
' Create our command
Dim myCommand As OleDbCommand = New OleDbCommand(strSQL,
myConnString)
Try
' Open the connection
myCommand.Connection.Open()
' execute the SQL
UpdateData = myCommand.ExecuteNonQuery()
Catch ex As OleDbException
MsgBox("An error was thrown by the ADO.Net component in
the GetData function. Error Details: " & _
vbCr & ex.Message, MsgBoxStyle.Exclamation, "Error!")
Debug.WriteLine("SQL Statement: " & strSQL)
UpdateData = Nothing
Finally
' Close the connection and destroy our connection object
myCommand.Connection.Close()
myConnString = Nothing
myCommand = Nothing
End Try
End Function

End Module


Mar 22 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: SamSpade | last post by:
There seems to be two ways to put things on the clipboard ( I don't mean different formats): SetClipboardData and OleSetClipboard If I want to get data off the clipboard do I care how it was put...
3
by: Ajay Krishnan Thampi | last post by:
I have a slight problem implementing 'drag and drop' from a datagrid to a tree-view. I have pasted my code below. Someone please advice me on what to do...pretty blur right now. ==code== ...
0
by: Paul Rempel | last post by:
Hi, I would like to make a web page where i can drag a selection of files from Windows Explorer to a spot on the web page and then have the page do something with the list of files names. ...
6
by: jojobar | last post by:
Hello, I look at the asp.net 2.0 web parts tutorial on the asp.net web site. I tried to run it under firefox browser but it did not run. If I want to use this feature in a commercial product...
1
by: WhatsPHP | last post by:
Hi Can anybody tell me how to upload a file by dragging it onto a web page? Using the <input = "file" .....> it is possible to upload files, but files cannot be dragged onto web pages for...
0
by: Ellen | last post by:
Hi! Please point me to the correct discussion if I am off base. We are beta testing a new Dot Net Framework application that allows us to upload documents of different file types for online...
1
by: milind28 | last post by:
Hi, I want to build ASP.NET web application like client can upload the photo or any type of file by simply drag the file from wondow explorer and drop it into container on the web page and then...
1
by: John Devlon | last post by:
Hi I would like to create a file upload system, using file drag and drop functionality. Does anyone know how ? John
2
by: deccio | last post by:
I have create an activex Control with Visual studio 2005 and framework 2.0 in c# to add drag & drop functionality to upload multi file. When I use it in a windows form it work fine. Infact if I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.