Upload File from Client to server

Posted on 2009-02-16
Last Modified: 2012-05-06
I have an 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


                End If

                'Copy file from client to the server?

                If myFile.Exists = True Then

                    myFile.CopyTo(pathToCopy & myFile.Name, True)


                	'Message file not found  exit.

                End If

End Sub


Open in new window

Question by:JenebyM
    LVL 14

    Accepted Solution

    Please see:
    "How to upload a file to a Web server in ASP.NET by using Visual Basic .NET"

    Author Comment


    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.

    LVL 12

    Expert Comment

    I don't see any Error in the posted code except for the text ERROR.

    Author Comment

    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?
    LVL 12

    Assisted Solution

    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.

    Author Closing Comment

    I have used the link provided by Junges and reframed all the statements as suggested by CB and this now works as desired.


    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
    In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now