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.
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.
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)
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
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
6 Points
96 Posts
file upload works in server but failed when uploaded from a client computer
Jul 17, 2018 01:36 PM|abfrank|LINK
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.
All-Star
54508 Points
14111 Posts
Re: file upload works in server but failed when uploaded from a client computer
Jul 17, 2018 01:40 PM|mudassarkhan|LINK
Share your code
Blog: ASPSnippets | Forum: ASPForums | Company: Excelasoft
All-Star
53131 Points
23681 Posts
Re: file upload works in server but failed when uploaded from a client computer
Jul 17, 2018 02:00 PM|mgebhard|LINK
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.
Member
6 Points
96 Posts
Re: file upload works in server but failed when uploaded from a client computer
Jul 17, 2018 02:04 PM|abfrank|LINK
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
All-Star
53131 Points
23681 Posts
Re: file upload works in server but failed when uploaded from a client computer
Jul 17, 2018 02:34 PM|mgebhard|LINK
I would remove the Try...Catch. It's not clear what smartobj.alertwindow() does but it might be hiding the actual error.
All-Star
54508 Points
14111 Posts
Re: file upload works in server but failed when uploaded from a client computer
Jul 18, 2018 07:23 AM|mudassarkhan|LINK
Yes. As said remove Try Catch
Blog: ASPSnippets | Forum: ASPForums | Company: Excelasoft
Member
740 Points
321 Posts
Re: file upload works in server but failed when uploaded from a client computer
Jul 18, 2018 10:01 AM|Abraham Qian|LINK
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