Link to home
Start Free TrialLog in
Avatar of edfreels
edfreelsFlag for United States of America

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(fileName & vbCrLf)
            Next
        End If
    End Sub

Thanks
Avatar of Jens Fiederer
Jens Fiederer
Flag of United States of America image

What mechanism do you mean to use to "upload", and where to?

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.).
Avatar of edfreels

ASKER

ah sorry,

Should have specified.  Using VB2005 and uploading to the intranet.  My upload string needs to be something like this \\fileserver1\intranet\marketing\st<nodeid)
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.
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\wilcointranet\marketingpromotion\st[NodeID]"

        Dim files As String() = Me.TextBox5.Text.Split(vbCrLf)
        For Each file As String In files
            'Remove unwanted character
            file = file.Replace(Chr(10), "")

            If file.Trim() <> "" Then
                'copy file
                My.Computer.FileSystem.CopyFile(file, _
                    IO.Path.Combine(destinationFolder, 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_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        Dim connectionString As String = _
 "Data Source=WHSQL2K301;Initial Catalog=WilcoIntranet;Persist Security Info=True;User ID=coldfusion;Password=coldfusion;"

        Dim cn As New SqlClient.SqlConnection(connectionString)
        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"
?
ok,  I will put that in, what do I need to do after that"?
ASKER CERTIFIED SOLUTION
Avatar of Jens Fiederer
Jens Fiederer
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial