0
I need to return a file in my action so that the client can download it. In my current code, the file is being saved on server.
[HttpGet]
public JsonResult ExibirPrintRPA(int? id)
{
string _nameFile = string.Empty;
EmissaoPrintRPA lemissao = new EmissaoPrintRPA();
EmissaoPrintRPA emissaoPrints = _EmissaoPrintRPAApplicationService.GetById(lemissao);
var _imagem = emissaoPrints.ST_IMAGEM;
_imagem = _imagem.Replace(" ", "+");
int mod4 = _imagem.Length % 4;
if (mod4 > 0)
{
_imagem += new string('=', 4 - mod4);
}
var _img = Convert.FromBase64String(_imagem);
var _filePath = string.Format("{0}\\{1}.{2}",
Server.MapPath("~/Files/Downloads"), _nameFile, "jpeg");
using (var fs = new FileStream(_filePath, FileMode.Create))
{
fs.Write(_img, 0, _img.Length);
fs.Flush();
}
return Json(new
{
file = string.Format("{0}.{1}", _nameFile, "jpeg"),
path = _filePath
});
}
Who defines where the file is saved is the client, you cannot control it by the server.
– Jéf Bueno
@LINQ, yes I understand but the way the code posted the file is being saved in the project folder, there in the Server and not saved in the user’s machine.
– hard123
Ah, wow, that’s not what you meant by reading the question. You’re using ASP.NET Core?
– Jéf Bueno
No, I’m using ASP.net MVC
– hard123