locked
file upload works in server but failed when uploaded from a client computer RRS feed

  • Question

  • User-1379762086 posted

    Dear all,

            Please am in need of your help, i have an asp.net vb application that allow users to upload excel file to the server. After deploying the application on an IIS server, the upload works well when i upload a file from server but failed when i tried to upload a file from a client computer. This problem happens with no exception message.

    Tuesday, July 17, 2018 1:36 PM

All replies

  • User-1171043462 posted

    Share your code

    Tuesday, July 17, 2018 1:40 PM
  • User475983607 posted

    Dear all,

            Please am in need of your help, i have an asp.net vb application that allow users to upload excel file to the server. After deploying the application on an IIS server, the upload works well when i upload a file from server but failed when i tried to upload a file from a client computer. This problem happens with no exception message.

    Sounds like a design error.  Keep in mind that a web server cannot access files on a client machine.  The user must select files and click a submit button.

    Rather than making us guess, consider posting code that reproduces the issue so we can see what you're doing.

    Tuesday, July 17, 2018 2:00 PM
  • User-1379762086 posted

    Thank you @Madussarkhan,

                  I notice the upload is actually happening but where it is failing is reading the file and displaying it on the gridview, however everything works well when i do it from the server. Below is my code

    Sub Upld()

    Dim intFileNameLength As Integer

    Dim strFileNamePath As String = ""

    ''Dim strFileNameOnly As String = ""

    Try

    'If Not (Myfile.PostedFile Is Nothing) Then

    Dim img As FileUpload = CType(Myfile, FileUpload)

    If img.HasFile AndAlso Not img.PostedFile Is Nothing Then

    Dim File As HttpPostedFile = Myfile.PostedFile

    Dim strFileNameOnly As String = Path.GetFileName(Myfile.PostedFile.FileName)

    ''strFileNamePath = Myfile.PostedFile.FileName

    ''intFileNameLength = InStr(1, StrReverse(strFileNamePath), "\")

    ''strFileNameOnly = Mid(strFileNamePath, (Len(strFileNamePath) - intFileNameLength) + 2)

    ' lblerror.Text = Server.MapPath("~/Upload/" & strFileNameOnly)

    If IO.File.Exists(Server.MapPath("~/Upload/" & strFileNameOnly)) Then

    IO.File.Delete(Server.MapPath("~/Upload/" & strFileNameOnly))

    End If

    Myfile.PostedFile.SaveAs(Server.MapPath("~/Upload/" & strFileNameOnly))

    Session("strFil1") = strFileNameOnly

    'Dim FTPAddress As String = "http://localhost:10039/Prime"

    'Dim fileInfo As IO.FileInfo = New IO.FileInfo(strFileNamePath)

    'uploadFileUsingFTP("ftp://" + FTPAddress + "/Upload/" + strFileNameOnly, strFileNamePath)

    Dim sConnectionString As String

    Dim objConn As OleDbConnection

    If Me.DrpExcelType.SelectedValue = "0" Then

    smartobj.alertwindow(Me.Page, "Please Select an Upload MS-Office Excel Type", "Prime")

    Exit Sub

    End If

    If Me.DrpExcelType.SelectedValue = "1" Then

    sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Server.MapPath("~/Upload/" + strFileNameOnly) + ";" + "Extended Properties=Excel 8.0;"

    objConn = New OleDbConnection(sConnectionString)

    Else

    sConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Server.MapPath("~/Upload/" + strFileNameOnly) + ";" + "Extended Properties=""Excel 12.0 Xml;HDR=YES;"""

    objConn = New OleDbConnection(sConnectionString)

    End If

    objConn.Open()

    Dim objCmdSelect As OleDbCommand = New OleDbCommand("SELECT * FROM [sheet1$] where Accountnumber <> null", objConn)

    Dim objAdapter1 As OleDbDataAdapter = New OleDbDataAdapter()

    Dim custCB As OleDbCommandBuilder = New OleDbCommandBuilder(objAdapter1)

    objAdapter1.SelectCommand = objCmdSelect

    Dim objDataset1 As DataSet = New DataSet()

    objAdapter1.AcceptChangesDuringFill = False

    objAdapter1.Fill(objDataset1, "Payment")

    Me.GridView1.DataSource = objDataset1.Tables(0).DefaultView

    GridView1.DataBind()

    objConn.Close()

    If Me.GridView1.Rows.Count > 0 Then

    upload.Enabled = False

    Me.Button1.Enabled = True

    Me.GridView1.Visible = True

    Else

    upload.Enabled = True

    Me.Button1.Enabled = False

    Me.GridView1.Visible = False

    End If

    ''Dim proc As String = "Exec proc_Checkaccount"

    ''Dim conrec As Integer = con.SqlDs(proc).Tables(0).Rows.Count

    ''If conrec > 0 Then

    '' For Each dr As DataRow In con.SqlDs(proc).Tables(0).Rows

    '' Me.ListBox1.Visible = True

    '' smartobj.loadListBox(Me.ListBox1, proc)

    '' Me.Button1.Enabled = False

    '' Next

    '' Me.Label6.Visible = True

    '' Me.Label6.Text = conrec & " Failed Account"

    ''Else

    '' Me.Label6.Text = conrec & " Failed Account"

    '' Me.Button1.Enabled = True

    '' Me.ListBox1.Visible = False

    ''End If

    End If

    Catch ex As Exception

    smartobj.alertwindow(Me.Page, ex.Message & " " & ex.StackTrace, "Prime")

    End Try

    End Sub

    Tuesday, July 17, 2018 2:04 PM
  • User475983607 posted

    I would remove the Try...Catch.  It's not clear what smartobj.alertwindow() does but it might be hiding the actual error. 

    Tuesday, July 17, 2018 2:34 PM
  • User-1171043462 posted

    Yes. As said remove Try Catch

    Wednesday, July 18, 2018 7:23 AM
  • User-330142929 posted

    Hi Abfrank,

    According to your description and codes, I think it may be caused by a permission problem, please try to give the corresponding permissions to the Upload folder. Such as the following.

    In addition, I am not clear about your web server environment. It seems your code doesn’t have any problems. Could you please post more details about your problem? such as, how did you see that the file was not uploaded, and the upload code was executed correctly? Could you please tell me about your IIS environment?

    Look forward to your reply.

    Best Regards

    Abraham

    Wednesday, July 18, 2018 10:01 AM