File Upload issues with WebClient.UploadFile

Discussion in 'ASP .Net' started by Phillip N Rounds, Feb 2, 2006.

  1. I'm having problems using the WebClient.UploadFile() command.
    I have MySender.ASPX which is supposed to upload two files to the server.
    There is also ConsumeFileUpload.aspx which is intended to handle receipt of
    the files. Pertinent code for each is below.

    When I run the process locally in debug mode, everything works great (
    VS.NET 2003 , ASP 1.1 ).
    When I run locally on the server, everything works great.
    When I try to remotely upload files, I get an error: THE REMOTE SERVER

    I have given both ASPNET & NETWORK SERVICE Write/Modify permissions in the
    target directory.

    Any Suggestions

    Button_Click in MySender.ASPX
    string Small = "c:\\MySmall.jpg";
    string Large = "c:\\MyBgPicture.jpg";
    System.Net.WebClient MyWebClient = new System.Net.WebClient();
    string URI="";
    string SUBDIR = "";
    util.GetLocationSettings( ref URI, ref SUBDIR);
    string uri = URI + "/" + SUBDIR + "/ConsumeFileUpload.aspx";
    byte[] by = MyWebClient.UploadFile( uri , "POST", this.Small);
    byte[] by2 = MyWebClient.UploadFile( uri , "POST", this.Large);
    catch ( Exception ex )
    EventLog log = new System.Diagnostics.EventLog();
    log.WriteEntry( ex.Message);

    Page_Load code in my ConsumeFileUpload.ASPX

    if ( util==null ) util = new Utilities();
    string URI = "";
    string SUBDIR = "";
    util.GetLocationSettings( ref URI, ref SUBDIR ); //
    Util.GetLocationSettings gets the Host Location Info, ultimately giving the
    directory to save the file in. This is OK
    SUBDIR = SUBDIR.Trim();
    string path = "/" + SUBDIR + "/images/";
    // path is the path, relative to the host site, into which to put the
    HttpFileCollection files;
    files = Page.Request.Files;
    for(int index=0; index < files.AllKeys.Length; index++)
    HttpPostedFile postedFile = files[index];
    string fileName = null;
    int lastPos = postedFile.FileName.LastIndexOf("\\");
    if ( lastPos < 0) fileName = postedFile.FileName;
    else { fileName = postedFile.FileName.Substring(++lastPos); }
    // This gives us simply MyPicture.jpg
    path = path.Trim();
    fileName = fileName.Trim();
    fileName = path + fileName;
    string sMapPath = MapPath( fileName );
    // This is where it tis to be saved, and gives the correct spot

    EventLog log = new System.Diagnostics.EventLog();
    log.Log = "Application Log";
    log.WriteEntry( "Saving: " + sMapPath, EventLogEntryType.Information);
    sMapPath = sMapPath.Trim();
    { postedFile.SaveAs( MapPath( fileName ) ); }
    catch ( Exception ex )
    log.Log = "Application Log";
    log.WriteEntry( "Exception:" + ex.Message, EventLogEntryType.Error);
    log.WriteEntry( "MapPath: " + sMapPath, EventLogEntryType.Error );
    Phillip N Rounds, Feb 2, 2006
    1. Advertisements

  2. Phillip N Rounds

    Bruce Barker Guest

    your remote server probably requires nt authenication. if you conect to your
    webserver locally, it can use your network creditials because it has a
    primary token. if it is not a local connection, then is has a secondary
    token which can not be used for any network resource.

    set you webserver to use a known domain accout with permission to the remote
    server,. or switch to kerberos.

    -- bruce (

    Bruce Barker, Feb 2, 2006
    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.