Articles in this section
Category / Section

How to download the uploaded file in browser?

1 min read

Description

You can download the uploaded file in browser.

Solution

We need to save the uploaded file in particular path and pass the filename to the codebehind by using the success function in UploadBox as illustrated in the following code example.

 

@(Html.EJ().Uploadbox("CECommissionsSpreadsheet").SaveUrl("FileUpload/UploadCESpreadsheet").AllowDragAndDrop(true).ExtensionsAllow(".xls, .xlsx").ClientSideEvents(e=>e.Success("OnSuccess"))) 
 
<script> 
    function OnSuccess(args,file) { 
 
        window.location = '/FileUpload/Download?file=' + args.files.name.split(".xls")[0].concat(".csv"); 
    
    } 
</script> 

 

 [HttpGet] 
 public virtual ActionResult Download(string file) 
 { 
      var fileName = Path.GetFileName(file); 
      var destinationPath = Path.Combine(Server.MapPath("~/App_Data"), fileName); 
      return File(destinationPath, "application/vnd.ms-excel", file); 
 } 

 

 

Please find the sample below,

 

Sample: Sample 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please  to leave a comment
Access denied
Access denied