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

Open in new window

JenebyMAsked:
Who is Participating?
 
Daniel JungesCommented:
Please see:
"How to upload a file to a Web server in ASP.NET by using Visual Basic .NET"
http://support.microsoft.com/kb/323245
0
 
JenebyMAuthor Commented:
Junges

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.

 
0
 
CB_ThirumalaiCommented:
I don't see any Error in the posted code except for the text ERROR.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
JenebyMAuthor Commented:
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?
0
 
CB_ThirumalaiCommented:
I guess you are doing the file upload differently.  Please refer the link provided by junges.  It tells the way how the file should be copied to the desired location.  You may need to reframe the statements and use PostedFile property.
0
 
JenebyMAuthor Commented:
I have used the link provided by Junges and reframed all the statements as suggested by CB and this now works as desired.

Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.