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
    webclient.UploadFile("http://127.0.0.1/ECSWebServices/UploadItem.aspx",
    "POST", "C:\Test.txt")

    and the file ends up looking like:

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

    This is a test file.
    -----------------------8c8a61883d4721e


    How do I get rid of the header/footer?

    TIA - Jeff.
     
    UJ, Sep 14, 2006
    #1
    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
     
    Tim_Mac, Sep 15, 2006
    #2
    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.

    Cheers,
     
    Joerg Jooss, Sep 16, 2006
    #3
    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.