How to pass filepath + filename from File Upload to controller and vice versa

Dear Syncfuction,


Sorry as I am quite new to ASP.NET Core, I manage to implement File Uploader into the edit.cshtml.

<div id = "ControlRegion2">

                <div class="col-lg-8 control-section">

                <div class="control_wrapper">

                    <ejs-uploader id="UploadFiles" removing="onFileRemove" success="onSuccess"

                            dropArea=".control-fluid" multiple="false" autoUpload="true"

                            asyncSettings="@asyncSettings">

                    </ejs-uploader>

                </div></div></div>

but how to pass back filePath + Filename to controller and eventually save  filePath + Filename  into MSSQL server? 

Can help to provide an example for this?

Also, any example for loading FilePath + Filename from controller and make File Upload control preloaded with FilePath + Filename?

Your help is very much appreciated.

Thanks,

Chen Chee Weng


2 Replies

DR Deepak Ramakrishnan Syncfusion Team May 23, 2022 06:33 PM UTC

Hi Chee,


We are currently validating your requirement , We will update the details in two business days (25th ,May 2022) .


Thanks,

Deepak R.



UD UdhayaKumar Duraisamy Syncfusion Team May 25, 2022 03:46 PM UTC

Hi Chee,


Query 1 : how to pass back filePath + Filename to controller and eventually save  filePath + Filename  into MSSQL server?


When we select a file for upload, on the client-side we can’t get the filepath because of security purposes. Once the file is uploaded, on the controller side we can get the file path. By using that you can save files from the controller to the MSSQL server.


Please refer to the below code snippet and screenshot for more details.

public void Save(IList<IFormFile> UploadFiles)

        {

            long size = 0;

            // for normal upload

            try

            {

                foreach (var file in UploadFiles)

                {

                    var filename = ContentDispositionHeaderValue

                                    .Parse(file.ContentDisposition)

                                    .FileName

                                    .Trim('"');

                    filename = hostingEnv.WebRootPath + $@"\{filename}";

                    size += file.Length;

                    if (!System.IO.File.Exists(filename))

                    {

                        using (FileStream fs = System.IO.File.Create(filename))

                        {

                            file.CopyTo(fs);

                            fs.Flush();

                        }

                    }

                }

            }


Screenshot :

Query 2 : any example for loading FilePath + Filename from controller and make File Upload control preloaded with FilePath + Filename?


The uploader control allows you to preload the list of files that are uploaded to the server. By default, the files are configured with uploaded successfully state on the rendering file list.

We can preload the files using only below mentioned properties:

*   Name

*   Size

*   Type


Online Demo : Example of Preload Files in ASP.NET Core File Upload Control


Regards,

Udhaya Kumar D.


Attachment: EJ2_ASP_Core_Uploader_38ba8dfd.zip

Loader.
Up arrow icon