![]() ![]() Through the use of a HTTP Handler you can download a file from a memory stream without creating an orphaned ASP.Net page. The last thing we need to do is to create a simple HTML Form that will post will to the Handler (Download.aspx).Īs you can see, this solution is pretty straight forward. Create a header for the file from the names of the StreamWriter sw = new StreamWriter(ReturnStream) Create a streamwriter to write to the memory stream String SqlString = "select * from dbo.Orders" String cn = "Persist Security Info=False Integrated Security=false User ID=sa Pwd=foo database=northwind server=foo Connect Timeout=30" You can open a stream to a Uri using WebClient class. You should note that RadPdfViewer runs on the client side, so saving must happen using the SaveFileDialog. MemoryStream ReturnStream = new MemoryStream() First, you should open a stream from the Uri you have, store this stream, and later when the user tries to save the file, you will pass this stream to the user. Create the return memorystream object that will hold Public class DownloadHandler : IHttpHandler This handler implements three methods, two of which are required by the IhttpHandler interface and one which is used to retirieve data from the database and return it as a memory stream. ![]() The first step in this example is to create the HTTP Handler. One way to overcome this is to use a HTTP Handler to execute the code that generates the text file and sends it back to the browser. Though this methodology worked, it left an orphaned ASP.NET page open after the download was complete. In a previous article I showed an example in which a file was created from a memory stream and sent back to the browser as a text file via an ASP.NET page. This article will show you how to buffer data into a MemoryStream and output the buffered data back to the browser as a text file using a HTTP Handler. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |