?
Solved

Command Button Upload Code

Posted on 2007-08-02
7
Medium Priority
?
234 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:edfreels
  • 4
  • 3
7 Comments
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 19618978
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.).
0
 
LVL 1

Author Comment

by:edfreels
ID: 19619071
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)
0
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 19620581
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.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:edfreels
ID: 19620627
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
0
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 19624180
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"
?
0
 
LVL 1

Author Comment

by:edfreels
ID: 19624190
ok,  I will put that in, what do I need to do after that"?
0
 
LVL 23

Accepted Solution

by:
Jens Fiederer earned 2000 total points
ID: 19624266
Assuming you REALLY want a path like
\\fileserver1\wilcointranet\marketingpromotion\st13
when the NodeID is 13
all you need to do is append
"\\fileserver1\wilcointranet\marketingpromotion\st"
to the Value of ListBox1
and you have a valid filename.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month15 days, 3 hours left to enroll

840 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