JenebyM
asked on
Upload File from Client to server
I have an asp.net web application. In this section I have an UploadFile and Button to upload a file from a client PC to a Web Server. This works on localhost where the server and client are the same, but I need for this to work on the production server with a PC connecting from the internet.
<input ID="UploadFile" runat="server" name="UploadFile" type="file" />
<asp:imagebutton id="bttnUpload" runat="server" ImageUrl="~/_images/Upload.jpg"></asp:imagebutton>
Protected Sub bttnUpload_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles bttnUpload.Click
Dim myFile As New FileInfo(UploadFile.Value)
'Set server location where file will be uploaded to.
Dim pathToCopy = Server.MapPath("~/Files/Docs/CRM/" & Session("CompCode") & "/Leads/")
'Check whether location has been created. Manually set write permissions to the directory.
If Not Exists(pathToCopy) Then
CreateDirectory(pathToCopy)
End If
'Copy file from client to the server?
If myFile.Exists = True Then
myFile.CopyTo(pathToCopy & myFile.Name, True)
Else
'Message file not found exit.
End If
End Sub
ERROR
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I don't see any Error in the posted code except for the text ERROR.
ASKER
ERROR
File Doc6.txt not found at specified location. i.e C:\WINDOWS\system32
The file's physical location on the client pc is C:\Temp\Doc6.txt
This exception message shows that uploadFile is looking for Doc6.txt in a different location i.e C:\WINDOWS\system32
Does this help?
File Doc6.txt not found at specified location. i.e C:\WINDOWS\system32
The file's physical location on the client pc is C:\Temp\Doc6.txt
This exception message shows that uploadFile is looking for Doc6.txt in a different location i.e C:\WINDOWS\system32
Does this help?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have used the link provided by Junges and reframed all the statements as suggested by CB and this now works as desired.
Thanks.
Thanks.
ASKER
I am not sure whether you actually looked at my code.! I have looked at the link and spent the last 45 mins replicating that info.
Apart from minor syntax changes there is not much that is fundamentally different.
The problem I have shown at the end of my code as the error also appears on this one.
I have looked at a number of links on this issue so it would be useful to get someone to actually look at the code provided rather than just sending another link. I am sure an experts review of my code will actually reveal what is missing. A link that supports an actual answer is of course useful.