We help IT Professionals succeed at work.
Get Started

Multiple ASP File upload boxes won't work when not all used

Last Modified: 2013-11-07
I have 5 asp fileupload controls on my page. If a user fills all 5 of them, when submited it works great. If they less than 5, then I get an error that says, "cannot find path". Can anyone look at my code and let me know how I can make it work whether 1, 2, 3, 4 or 5 files are uploaded? Thanks.
' Specify the path on the server to
            ' save the uploaded file to.
            Dim savePath As String = Server.MapPath("~/ServeeDocs/")
            Dim savePath2 As String = Server.MapPath("~/ServeeDocs/")
            Dim savePath3 As String = Server.MapPath("~/ServeeDocs/")
            Dim savePath4 As String = Server.MapPath("~/ServeeDocs/")
            Dim savePath5 As String = Server.MapPath("~/ServeeDocs/")
            ' Before attempting to perform operations
            ' on the file, verify that the FileUpload 
            ' control contains a file.
            ' Get the name of the file to upload.
            Dim fileName As String = FileUpload1.FileName
            Dim fileName2 As String = FileUpload2.FileName
            Dim fileName3 As String = FileUpload3.FileName
            Dim fileName4 As String = FileUpload4.FileName
            Dim fileName5 As String = FileUpload5.FileName
            ' Append the name of the file to upload to the path.
            savePath += fileName
            savePath2 += fileName2
            savePath3 += fileName3
            savePath4 += fileName4
            savePath5 += fileName5
            ' Call the SaveAs method to save the 
            ' uploaded file to the specified path.
            ' This example does not perform all
            ' the necessary error checking.               
            ' If a file with the same name
            ' already exists in the specified path,  
            ' the uploaded file overwrites it.
            ' Notify the user of the name the file
            ' was saved under.
            UploadStatusLabel2.Text = "Your file was saved as " & fileName
            Label535.Text = fileName
            Label536.Text = fileName2
            Label537.Text = fileName3
            Label538.Text = fileName4
            Label539.Text = fileName5
            Dim strConn3 As String = "Data Source=sql2005-5.reinventinc.com;Integrated Security=false;Initial Catalog=phcampbell;User ID=re100679;Password=church101"
            'Dim strConn3 As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Client.mdf;Integrated Security=True;User Instance=True"
            Dim MySQL3 As String = "INSERT INTO ScannedDocs (Docs, OrdersID, OwnerID) VALUES (@Docs, @OrdersID, @OwnerID); INSERT INTO ScannedDocs (Docs, OrdersID, OwnerID) VALUES (@Docs2, @OrdersID, @OwnerID); INSERT INTO ScannedDocs (Docs, OrdersID, OwnerID) VALUES (@Docs3, @OrdersID, @OwnerID); INSERT INTO ScannedDocs (Docs, OrdersID, OwnerID) VALUES (@Docs4, @OrdersID, @OwnerID); INSERT INTO ScannedDocs (Docs, OrdersID, OwnerID) VALUES (@Docs5, @OrdersID, @OwnerID)"
            Dim Conn3 As New SqlConnection(strConn3)
            Dim Cmd3 As New SqlCommand(MySQL3, Conn3)
            Cmd3.Parameters.Add(New SqlParameter("@Docs", Label535.Text))
            Cmd3.Parameters.Add(New SqlParameter("@Docs2", Label536.Text))
            Cmd3.Parameters.Add(New SqlParameter("@Docs3", Label537.Text))
            Cmd3.Parameters.Add(New SqlParameter("@Docs4", Label538.Text))
            Cmd3.Parameters.Add(New SqlParameter("@Docs5", Label539.Text))
            Cmd3.Parameters.Add(New SqlParameter("@OrdersID", NewJobNumber.Value.ToString()))
            Cmd3.Parameters.Add(New SqlParameter("@OwnerID", Variable.ToString()))

Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE