Send file to Client
-
Hi. I'm using a third party made module to generate pdf files. The user clicks a button, The code generates a pdf i memory and now a want to be able to send the pdf as a file to the client in a way where he gets the popup where he can choose to view or save the file. When the pdf file is ready (in memory) I can use 2 methods. one to write the file physically to disk (to a Path or to a filestream) or one to get the file as a byte[]. I want to send the file to the client _without_ first writing the file to disk. I've bee trying to do this with a filestream and Response.WriteFile. But this results in nothing happens. If I write the file to disk first and the reload it in Response.WriteFile, then it works. So the question is: How can I send a file that is not on disk (only i memory) to the client without writing the file to disk?
-
Hi. I'm using a third party made module to generate pdf files. The user clicks a button, The code generates a pdf i memory and now a want to be able to send the pdf as a file to the client in a way where he gets the popup where he can choose to view or save the file. When the pdf file is ready (in memory) I can use 2 methods. one to write the file physically to disk (to a Path or to a filestream) or one to get the file as a byte[]. I want to send the file to the client _without_ first writing the file to disk. I've bee trying to do this with a filestream and Response.WriteFile. But this results in nothing happens. If I write the file to disk first and the reload it in Response.WriteFile, then it works. So the question is: How can I send a file that is not on disk (only i memory) to the client without writing the file to disk?
I found I solution my self: byte[] theData = theDoc.GetData(); Page.Response.ContentType = "application/pdf"; Page.Response.AppendHeader("content-disposition", "attachment; filename=MyPDF.PDF"); Page.Response.AppendHeader("content-length", theData.Length.ToString()); Page.Response.BinaryWrite(theData);