edfreels
asked on
Command Button Upload Code
I have the following code for a command button. As you can see when executed you are able to choose files. Then the file path drops down in the textbox. I need to know what code to put in for another command button that would upload these files.
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
Dim MyDialog As New OpenFileDialog()
MyDialog.InitialDirectory = False
MyDialog.ShowHelp = True
MyDialog.ShowReadOnly = False
MyDialog.Multiselect = True
If MyDialog.ShowDialog() = DialogResult.OK Then
For Each fileName As String In MyDialog.FileNames
Me.TextBox4.AppendText(fil eName & vbCrLf)
Next
End If
End Sub
Thanks
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
Dim MyDialog As New OpenFileDialog()
MyDialog.InitialDirectory = False
MyDialog.ShowHelp = True
MyDialog.ShowReadOnly = False
MyDialog.Multiselect = True
If MyDialog.ShowDialog() = DialogResult.OK Then
For Each fileName As String In MyDialog.FileNames
Me.TextBox4.AppendText(fil
Next
End If
End Sub
Thanks
ASKER
ah sorry,
Should have specified. Using VB2005 and uploading to the intranet. My upload string needs to be something like this \\fileserver1\intranet\mar keting\st< nodeid)
Should have specified. Using VB2005 and uploading to the intranet. My upload string needs to be something like this \\fileserver1\intranet\mar
In that case, your command handler for the new button should be able to do its job with just File.Copy!
You might have some issues with permissions to the target machine, but if not this should be easy.
You might have some issues with permissions to the target machine, but if not this should be easy.
ASKER
jens,
Yea I have this code below, but I am having trouble figuring out the last part
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
Dim destinationFolder As String = "\\fileserver1\wilcointran et\marketi ngpromotio n\st[NodeI D]"
Dim files As String() = Me.TextBox5.Text.Split(vbC rLf)
For Each file As String In files
'Remove unwanted character
file = file.Replace(Chr(10), "")
If file.Trim() <> "" Then
'copy file
My.Computer.FileSystem.Cop yFile(file , _
IO.Path.Combine(destinatio nFolder, IO.Path.GetFileName(file)) , _
True)
End If
Next
MsgBox("Upload Complete!")
End Sub
In the destination folder where you see st[nodeid] I am not sure what to change that to, to get it to automatically query the nodeid. Here is the code on my listbox.
Private Sub ListBox1_SelectedIndexChan ged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChan ged
Dim connectionString As String = _
"Data Source=WHSQL2K301;Initial Catalog=WilcoIntranet;Pers ist Security Info=True;User ID=coldfusion;Password=col dfusion;"
Dim cn As New SqlClient.SqlConnection(co nnectionSt ring)
Dim da As New SqlClient.SqlDataAdapter()
da.SelectCommand = New SqlClient.SqlCommand()
With da.SelectCommand
.Connection = cn
.CommandType = CommandType.Text
'You need to change the CommandText Select Statement
' Change "NodeID" to the nodeID column name
' Change "StoreName " to the nodeID column name
' Change "StoresTable " to the name of the table in your database
.CommandText = _
"SELECT NodeID, NodeNbr FROM Node ORDER BY NodeName"
End With
Me.ListBox1.DisplayMember = "NodeName"
Me.ListBox1.ValueMember = "NodeID"
End Sub
Have any ideas?
Thanks
Yea I have this code below, but I am having trouble figuring out the last part
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
Dim destinationFolder As String = "\\fileserver1\wilcointran
Dim files As String() = Me.TextBox5.Text.Split(vbC
For Each file As String In files
'Remove unwanted character
file = file.Replace(Chr(10), "")
If file.Trim() <> "" Then
'copy file
My.Computer.FileSystem.Cop
IO.Path.Combine(destinatio
True)
End If
Next
MsgBox("Upload Complete!")
End Sub
In the destination folder where you see st[nodeid] I am not sure what to change that to, to get it to automatically query the nodeid. Here is the code on my listbox.
Private Sub ListBox1_SelectedIndexChan
Dim connectionString As String = _
"Data Source=WHSQL2K301;Initial Catalog=WilcoIntranet;Pers
Dim cn As New SqlClient.SqlConnection(co
Dim da As New SqlClient.SqlDataAdapter()
da.SelectCommand = New SqlClient.SqlCommand()
With da.SelectCommand
.Connection = cn
.CommandType = CommandType.Text
'You need to change the CommandText Select Statement
' Change "NodeID" to the nodeID column name
' Change "StoreName " to the nodeID column name
' Change "StoresTable " to the name of the table in your database
.CommandText = _
"SELECT NodeID, NodeNbr FROM Node ORDER BY NodeName"
End With
Me.ListBox1.DisplayMember = "NodeName"
Me.ListBox1.ValueMember = "NodeID"
End Sub
Have any ideas?
Thanks
Quite a jump from "upload" to SQL!
Anyway, one thing that I can tell you for certain is that you cannot use
Me.ListBox1.DisplayMember = "NodeName"
when you don't pull NodeName in your SELECT!
What happens if you use
.CommandText = _
"SELECT NodeID, NodeName FROM Node ORDER BY NodeName"
?
Anyway, one thing that I can tell you for certain is that you cannot use
Me.ListBox1.DisplayMember = "NodeName"
when you don't pull NodeName in your SELECT!
What happens if you use
.CommandText = _
"SELECT NodeID, NodeName FROM Node ORDER BY NodeName"
?
ASKER
ok, I will put that in, what do I need to do after that"?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Obviously you can upload only to computers that provide some facility to DO this, and there many possibilities (ftp, web services, copying using UNC paths, etc.).