Below is my code :
public class ActionDownloadAttribute : ActionFilterAttribute
{
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
filterContext.HttpContext.Response.AddHeader("content-disposition", "attachment; filename=" + "Report.pdf");
base.OnResultExecuted(filterContext);
}
}
[ActionDownload]
public ActionResult GeneratePdf()
{
List<Comment> comments = null;
using (var db = new CandidateEntities())
{
comments = db.Comments.ToList();
}
return new PdfActionResult("GeneratePdf", comments);
}
This above code gives the PDF file for download.But I want to Save it(Automatically) to specific path or Blob before downloading it.
Can anyone help me in the same?
When I looked originally at my answer it did not really brought a lot of value.So I will try to expand.
Not async
First I have exactly the same controller as you. Then I use restsharp to make a call to that URL
Now if you look at the response.RawBytes you can use that in methods below to upload the byte array directly to Azure :)
I call one of my 2 methods to either upload a byte[] or from stream
Let me know if this helps. It works for me in my azure environment. I have a webjob generating those files and saving them automatically on blob.
Updated : Async
If you would rewrite those methods to upload to Azure to be Async then having something like below would enable you to do following call :
I will be testing that method more in detail to confirm its behavior.
comments much welcome :D