WebClient.UploadFile adds stuff to the file.

Discussion in 'ASP .Net' started by UJ, Sep 14, 2006.

  1. UJ

    UJ Guest

    I'm trying to upload stuff using the UploadFile from WebClient and I've
    noticed that it adds header and footers to the stream.

    Is there any way to get rid of that automatically?

    I'm using
    "POST", "C:\Test.txt")

    and the file ends up looking like:

    Content-Disposition: form-data; name="file"; filename="test2.txt"
    Content-Type: application/octet-stream

    This is a test file.

    How do I get rid of the header/footer?

    TIA - Jeff.
    UJ, Sep 14, 2006
    1. Advertisements

  2. UJ

    Tim_Mac Guest

    you can be sure that there is something going on in your UploadItem.aspx
    page that is writing the header and footer.
    the UploadFile method works as you would expect it to.

    the sample code from the SDK is as follows:

    void Page_Load(object sender, EventArgs e)
    foreach(string f in Request.Files.AllKeys)
    HttpPostedFile file = Request.Files[f];
    file.SaveAs("c:\\inetpub\\test\\UploadedFiles\\" + file.FileName);

    what code are you using?
    Tim_Mac, Sep 15, 2006
    1. Advertisements

  3. UJ

    Joerg Jooss Guest

    Thus wrote UJ,
    That's a multipart/form-data request and supposed to look like that.

    Either use WebClient.UploadData() or make sure the server side knows how
    to deal with a multipart/form-data request.

    Joerg Jooss, Sep 16, 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.