- Home
- Forum
- ASP.NET Core - EJ 2
- Response does not reflect on client-side.
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.
SIGN IN To post a reply.
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,
Sample Link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/WebApplication1-836195530
Regards,
Sevvandhi N
SIGN IN To post a reply.
- 1 Reply
- 2 Participants
-
NB Naresh Bisht
- Mar 24, 2020 07:04 AM UTC
- Mar 25, 2020 01:47 PM UTC