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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to get file from datagrid dialog upload

Thread ID:





147264 Sep 4,2019 02:08 PM UTC Sep 9,2019 02:22 PM UTC ASP.NET Core - EJ 2 4
Tags: File Upload
Peter Barasits
Asked On September 4, 2019 02:08 PM UTC


How to get file (content) in the CRUD action on the Controller?

I send one file (and some property) from the datagrid custom dialog (like at a form):
<ejs-uploader id="photo" autoUpload="false" multiple="false" allowedExtensions="image/*" />

The controller received photo parameter is string: "C:\fakepath\[Filename].[extension]"

How to get file content?

I try 
byte[] photo = System.IO.File.ReadAllBytes(model.value.Photo);
But received exception: System.IO.DirectoryNotFoundException: 'Could not find a part of the path 'C:\fakepath\[filename].[extension]'.'

Peter Barasits
Replied On September 5, 2019 05:08 PM UTC

I use this demo code: https://ej2.syncfusion.com/aspnetcore/Uploader/FormSupport#/material
I need the controller code, to the get uploaded file content.

public IActionResult FormData(DataModel model){
  byte[] photo = System.IO.File.ReadAllBytes(model.value.Photo);  // And this get exception

Model is get correctly, but file get only file path, and path getting started c:\fakepath\
What the problem?

Narayanasamy Panneer Selvam [Syncfusion]
Replied On September 6, 2019 12:30 AM UTC

Hi Peter, 
Good day to you. 
Yes, you can convert uploaded files to binary format. Please refer the below link: https://ej2.syncfusion.com/aspnetcore/documentation/uploader/how-to/convert-image-into-binary-format-after-uploading/ 
Please let us know if you need any further assistance on this. 
Narayanasamy P.  

Peter Barasits
Replied On September 6, 2019 07:35 AM UTC

Hi Narayanasamy,

I tried this, but not working.
If set autoupload=false and send the form, will not call a save action.
If set autoupload=true, call a save action, but not send a file (UploadFiles.Count = 0).

Sevvandhi Nagulan [Syncfusion]
Replied On September 9, 2019 02:22 PM UTC

Hi Peter, 

Query 1: While setting autoupload=false and send the form, will not call a save action 
As we mentioned in the below documentation,autoUpload must be disabled and save& remove url must be null when you placing the uploader inside form. This is default behaviour. 

Query2: while setting autoupload=true, call a save action, but not send a file -UploadFiles.Count = 0 
This issue might occur when you have placed the submit button outside of the form. So we suggest you place the submit button inside the form. Also, you can get the files in the controller using the specified name attribute in control. Please refer the below code, 

          <form id="form1" method="post" action="/Home/Save"> 
              <ejs-uploader id="fileupload" autoUpload="false" multiple="false" allowedExtensions="image/*"> </ejs-uploader> 
              <div class="submitBtn"> 
                  <button class="submit-btn e-btn" id="submit-btn" type="submit">Submit</button> 
                  <div class="desc"><span>*This button is not a submit type and the form submit handled from externally.</span></div> 

public IActionResult Save(IList<IFormFile> fileupload) 
                foreach (var file in fileupload) 
                    if (fileupload != null) 
                        var filename = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); 
                        filename = hostingEnv.WebRootPath + $@"\{filename}"; 
                        if (!System.IO.File.Exists(filename)) 
                            //using (FileStream fs = System.IO.File.Create(filename)) 
                            //    file.CopyTo(fs); 
                            //    fs.Flush();  
                            Response.StatusCode = 204; 
                            Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = "File already exists."; 
            catch (Exception e) 
                Response.ContentType = "application/json; charset=utf-8"; 
                Response.StatusCode = 204; 
                Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = "No Content"; 
                Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = e.Message; 
            return Content(""); 

Please find the sample from below link, 

Sevvandhi N 


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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

Live Chat Icon For mobile
Live Chat Icon