This is a migrated thread and some comments may be shown as answers.

Send file along with another fields

5 Answers 278 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Erick
Top achievements
Rank 1
Erick asked on 11 May 2012, 12:18 AM
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?

5 Answers, 1 is accepted

Sort by
0
Jon Barron
Top achievements
Rank 1
answered on 01 Aug 2012, 06:36 PM
I would like an answer to this question as well.
0
Piyey
Top achievements
Rank 2
answered on 07 Aug 2012, 09:59 PM
I would like to know this too....
0
Erick
Top achievements
Rank 1
answered on 07 Aug 2012, 10:12 PM
I can't put it working this way until today. I'm starting thinking that it's impossible with the Kendo Uploader...
0
Jon Barron
Top achievements
Rank 1
answered on 07 Aug 2012, 10:52 PM
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.
0
Piyey
Top achievements
Rank 2
answered on 08 Aug 2012, 04:42 PM
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
Tags
Upload
Asked by
Erick
Top achievements
Rank 1
Answers by
Jon Barron
Top achievements
Rank 1
Piyey
Top achievements
Rank 2
Erick
Top achievements
Rank 1
Share this question
or