How do i generate a temporal PDF in my ASP.NET application so I get an temp URL for a generated PDF from an array of bytes ?

I use this but i think it could get simple:

//bytes[] arrayPDF exists before
string fileName = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".pdf";
File.WriteAllBytes(fileName, arrayPDF);

HtmlGenericControl obj = new HtmlGenericControl("embed");
obj.Attributes.Add("src", fileName);
obj.Attributes.Add("style","border-radius: 10px;position: relative;top:0;right:0;left:0;bottom:0;width:100%;height:620px;");
obj.Attributes.Add("height","600");
obj.Attributes.Add("type", "application/pdf");
form1.Controls.Add(obj);

My main problem is how to generate a temp file that i am sure that it would not stay in the server more than the request/show time

Related posts

Recent Viewed