Response does not reflect on client-side.

Hi, 
     I'm able to reflect the response from server-side in client-side, I have followed like the docs provided and also read all the thread here and on GitHub related to this also tried " Response.Headers.Add("status", "File already exists") " but I'm unable to solve this can you please send me a working project where if the file already exists in the directory then show the message "File already exists".

Thanks, I would really appreciate it.

1 Reply

SN Sevvandhi Nagulan Syncfusion Team March 25, 2020 01:47 PM UTC

Hi Naresh, 

Greetings from Syncfusion support. 

We have returned the status text as file exists if the file already saved in the server. And showcased the corresponding string in the client side. Kindly refer the below code, 

[index.cshtml] 

function onSuccess(args) { 
        if (args.e.target.getResponseHeader('status')) { 
            var status = args.e.target.getResponseHeader('status').split(",")[1]; 
            args.statusText = status; 
        } 
    } 

[HomeController.cs] 
 
public IActionResult Save(IList<IFormFile> UploadFiles) 
        { 
            try 
            { 
                foreach (var file in UploadFiles) 
                { 
                    if (UploadFiles != 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();  
                            } 
                        } 
                        else 
                        { 
                            Response.Clear(); 
                            Response.StatusCode = 204; 
                            Response.Headers.Add("status", "File Already Exists"); 
                        } 
                    } 
                } 
            } 
            catch (Exception e) 
            { 
                Response.Clear(); 
                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 below, 
 
 
Regards, 
Sevvandhi N 




Loader.
Up arrow icon