We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

force upload file

Thread ID:

Created:

Updated:

Platform:

Replies:

128861 Feb 13,2017 10:47 AM UTC Feb 20,2017 04:17 AM UTC ASP.NET MVC 6
loading
Tags: Uploadbox
Manolo
Asked On February 13, 2017 10:47 AM UTC

Hi,

I've some uploadbox out of form, and I need upload the files in synchronous.

so, how can I force upload files when I need?

I have not seen any method for force upload the files.

Thanks

Karthikeyan Viswanathan [Syncfusion]
Replied On February 14, 2017 08:53 AM UTC

Hi Manolo,      
     
Thanks for contacting Syncfusion Support.      
  
Yes, you can achieve this scenario using Ajax post without form element. Please find the below code snippet:      
     
<code>      
@Html.EJ().Uploadbox("UploadDefault").SaveUrl("SaveDefault").RemoveUrl("RemoveDefault").AsyncUpload(false)   
   
                       
 @Html.EJ().Button("btnclick").Type(ButtonType.Button).Text("Click")   
   
</code>      
<code>   
<script type="text/javascript">   
        $(function () {   
            $("#btnclick").click(function (args) {   
                var formdata = new FormData();   
                var _files = $("[name='UploadDefault']:not(.e-uploadinput)")[0].files.length;   
                for (var x = 0; x < _files; x++) {   
                    formdata.append("fileInput[" + x + "]"$("[name='UploadDefault']:not(.e-uploadinput)")[0].files[x]);   
                }   
                $.ajax   
                           (   
                                  {   
                                      url: '@Url.Action("SaveSynchronous""FileUpload")',  //'/Tab/QuickListTabContent',   
                                      type: 'POST',   
                                      data: formdata,   
                                      processData: false,   
                                      contentType: false,   
                                      cache: false,   
                                  }).done(function (result) {   
                                      $("[name='UploadDefault']:not(.e-uploadinput)").each(function () {   
                                              $(this).remove();   
                                      });   
                                      var inst = $("#UploadDefault").ejUploadbox("instance");   
                                      inst.updialog.data('ejDialog').close();   
                                  }   
                           );   
            });   
        });   
    </script>   
</code>   
<code>   
Controller   
[HttpPost]   
        public ActionResult SaveSynchronous(IEnumerable<HttpPostedFileBasefileInput)   
        {   
            if (fileInput != null)   
            {   
                foreach (var file in fileInput)   
                {   
                    var fileName = Path.GetFileName(file.FileName);   
                    var destinationPath = Path.Combine(Server.MapPath("~/App_Data"), fileName);   
                    file.SaveAs(destinationPath);   
                }   
                TempData["status"] = "Successfully Uploaded";   
                return RedirectToAction("FileUploadFeatures");   
            }   
            else   
            {   
                TempData["status"] = "Select a file to upload";   
                return RedirectToAction("FileUploadFeatures");   
            }   
   
        }   
   
   
</code>   
  
     
     
Regards,      
Karthikeyan V.     


Manolo
Replied On February 15, 2017 08:42 AM UTC

Thanks a lot!

Manolo
Replied On February 15, 2017 12:27 PM UTC

Ups... other question. In ajax petition. how can I add more parameters?

Some similar at this

 $.ajax({
                url: '@Url.Action("SaveSynchronous", "NuevasPoblaciones")', 
                type: 'POST',
                data: { fileInput: JSON.stringify(formdata), idConflicto: "1" },
                processData: false,               
                contentType: false,
                cache: false,
            }).done(function (result) {
                $("[name='ubFicheroCompetencia']:not(.e-uploadinput)").each(function () {
                    $(this).remove();
                });
                var inst = $("#ubFicheroCompetencia").ejUploadbox("instance");
                inst.updialog.data('ejDialog').close();
            }
            );

public ActionResult SaveSynchronous(IEnumerable<HttpPostedFileBase> fileInput, string idConflicto)
{
...}

When I add a new parameter, in controller, all parameters has null values

Karthikeyan Viswanathan [Syncfusion]
Replied On February 16, 2017 05:48 AM UTC

Hi Manolo,         
        
Thanks for your update.     
  
Yes, you can easily add more parameters in form data using the highlighted code below. Please find the code snippet:   
  
<code>   
  
$(function () {   
            $("#btnclick").click(function (args) {   
                var formdata = new FormData();   
                var _files = $("[name='UploadDefault']:not(.e-uploadinput)")[0].files.length;   
                for (var x = 0; x < _files; x++) {   
                    formdata.append("fileInput[" + x +"]", $("[name='UploadDefault']:not(.e-uploadinput)")[0].files[x]);   
                }   
                formdata.append("idConflicto", "1");   
                $.ajax   
                           (   
                                  {   
                                      url:'@Url.Action("SaveSynchronous", "FileUpload")',   
                                      type: 'POST',   
                                      data: formdata,   
                                      processData: false,   
                                      contentType: false,   
                                      cache: false,   
                                  }).done(function(result) {   
                                      $("[name='UploadDefault']:not(.e-uploadinput)").each(function() {   
                                             $(this).remove();   
                                      });   
                                      var inst = $("#UploadDefault").ejUploadbox("instance");   
                                     inst.updialog.data('ejDialog').close();   
                                  }   
                           );   
            });   
        });   
    </script>   
   
   
// Controller   
   
   
public ActionResultSaveSynchronous(IEnumerable<HttpPostedFileBase> fileInput,String idConflicto)   
        {   
               
        }   
</code>   
 
  



  
 


Manolo
Replied On February 17, 2017 08:25 AM UTC

Thanks again!

Karthikeyan Viswanathan [Syncfusion]
Replied On February 20, 2017 04:17 AM UTC

Hi Manolo,  
  
Thanks for the update.   
  
We are glad the suggestion helped you to achieve your requirement.   
  
Please let us know if you need further assistance.   
  
Regards,    
Karthikeyan V.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;