Problems with WebClient.UploadFile

Discussion in 'ASP .Net' started by David W, Oct 29, 2003.

  1. David W

    David W Guest

    I am trying to upload a file from a user's system to my web server. I
    found code using the WebClient.UploadFile method. However, the
    uploaded file is from the server's hard drive not the user's system.
    I don't want to use the input file method (as this will force the user
    to do unnessecary browsing and I know where the file will be:
    c:\test.txt for example). I am sure that I am just missing something
    simple. However, I can not figure out what it is. I keep getting the
    file from the server moved to the new location as opposed to the file
    from the user's system.

    Any suggestions??

    Below is the current version of the code:

    <%@ Import Namespace="System"%>
    <%@ Import Namespace="System.IO"%>
    <%@ Import Namespace="System.Net"%>
    <%@ Import NameSpace="System.Web"%>

    <Script language="C#" runat=server>

    public void UploadFile( Object s, EventArgs e )
    //Create the GUID used for the Uploaded File
    Guid strGuid = Guid.NewGuid();

    //The GUID is used for the Destination
    string strUploadURI = "http://localhost/upload.aspx?g=" +

    WebClient myWebClient = new WebClient();
    myWebClient.UploadFile(strUploadURI, "POST", "c:\\test.txt");

    info.InnerHtml = "<p>FILE UPLOADED</p>";


    <form runat="server">

    <input type="submit" value="Click ME" OnServerClick="UploadFile"

    <span id="info" Runat="Server" />

    David W, Oct 29, 2003
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.