I am facing an issue with the download file in the browser using base64 or binary string. On button click event, I am calling API on the server side and trying to return the file without saving it in the physical folder.
Q. Is it possible to download the file without saving it in the physical folder?
Q. If possible, what are the ways to do it in the asp.net webform?
I am stuck with lots of trials, any help would be appreciated.
** I have got the actual file, when I was trying to consume that API using postman, there is an option(while sending Request) to Send and Download
Q. How can that be done(like postman is allowing to download the file) using c#?
Note: I am getting base64 or binary from an API.
Exception on
Response.End();
:
{Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}
Thanks
What I have tried:
byte[] bytes = Encoding.ASCII.GetBytes(strBinary);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
HttpContext.Current.Response.AddHeader("Content-Length", Convert.ToString(bytes.Length));
HttpContext.Current.Response.BinaryWrite(bytes);
HttpContext.Current.Response.End();