Send file along with another fields

6 posts, 0 answers
  1. Erick
    Erick avatar
    3 posts
    Member since:
    Dec 2011

    Posted 10 May 2012 Link to this post

    I'm using Kendo Upload inside an ASP.NET WebForms page to upload a user picture (not multiple files, only one).

    It have a Save button that sends the values of many fields. I would like to send the file together with the values. Is there any way to do it with Ajax? Or with a normal Postback? Can someone please explain me how to do it?
  2. Jon Barron
    Jon Barron avatar
    24 posts
    Member since:
    Oct 2012

    Posted 01 Aug 2012 Link to this post

    I would like an answer to this question as well.
  3. Piyey
    Piyey avatar
    2 posts
    Member since:
    Sep 2011

    Posted 07 Aug 2012 Link to this post

    I would like to know this too....
  4. Erick
    Erick avatar
    3 posts
    Member since:
    Dec 2011

    Posted 07 Aug 2012 Link to this post

    I can't put it working this way until today. I'm starting thinking that it's impossible with the Kendo Uploader...
  5. Jon Barron
    Jon Barron avatar
    24 posts
    Member since:
    Oct 2012

    Posted 07 Aug 2012 Link to this post

    As it turns out, this is done almost exactly the same way as any other form post. The example below is using MVC.

    First off, make sure your form's enctype is set to enctype="multipart/form-data" . Example:
    @using (Html.BeginForm("BeginUpload","Upload"FormMethod.Postnew { target="upload_target"id="uploadForm"
    enctype="multipart/form-data"onsubmit="return beginUpload();"style="width:45%"})) { 

    - The target is an iframe I have on the page that fetches upload status via ajax calls.

    After you deal with saving your form's values in the view model, you can save the file(s) that were uploaded by accessing the Request.Files collection; there will be one entry in the collection for each file in your form.
     foreach(HttpPostedFileBase file in Request.Files) 
        file.SaveAs(file.FileName);

    You will obviously want to change the file name to point to a path on your server, as well as various other checks on the uploaded file, but that's the basics of it.
  6. Piyey
    Piyey avatar
    2 posts
    Member since:
    Sep 2011

    Posted 08 Aug 2012 Link to this post

    If we are talking about the same request, this will really helps you, I realize what I want with this article, I hope this helps you too.

    http://www.west-wind.com/weblog/posts/2010/Sep/07/Using-jQuery-to-POST-Form-Data-to-an-ASPNET-ASMX-AJAX-Web-Service

    Regards,
    Paúl Somarriba
Back to Top