473,387 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How can I serve a dynamic file, and then clean it up?

I wrote an aspx page that creates a .pdf file upon request and transfers the
file to the client for viewing (via an Adobe Acrobat plug-in). Afterwards,
the file is no longer needed and should be deleted from the server. Here is
a code snippet as an example:

Response.ContentType = "application/pdf";
Response.Clear();
Response.TransmitFile(filename);
Response.Flush();
//Response.End();
System.IO.File.Delete(filename);

Could someone suggest a better way of getting the dynamic file to the client
while maintaining a clean server?
Jul 21 '08 #1
2 1430
Instead of writing to the file to disk, you would use a memory stream.
Then transfer the binary data into a byte array, and use the Response
object to output it to the client.
Instead of using Response.TransmitFile use:

Response.BinaryWrite(TemporaryFileByteArray);

DotCodeDump: http://www.dotcodedump.com

+Ian Lintner
Jul 21 '08 #2
I'm actually using a 3rd party tool that generates the file. I have no
control over that. However, your suggestion helped me load the file into a
byte array, delete the file, and then write the binary data to the client.
Thanks!

"IanL" wrote:
Instead of writing to the file to disk, you would use a memory stream.
Then transfer the binary data into a byte array, and use the Response
object to output it to the client.
Instead of using Response.TransmitFile use:

Response.BinaryWrite(TemporaryFileByteArray);

DotCodeDump: http://www.dotcodedump.com

+Ian Lintner
Jul 21 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Joshua McCulloch | last post by:
I have setup Apache 2.0.50 and JBoss 3.2.5 using mod_jk2. My application is defined to operate in the root context (http://servername/) by creating a WEB-INF/jboss-web.xml I am serving static...
2
by: mep | last post by:
Hi, After lookup in cherrypy site and google for a while, I haven't found any information about cherrypy how to serve dynamic binary file(some generated charts).Is there any easy way to do this?...
3
by: Chris Tanger | last post by:
I am creating a class that has a method "Write" that I wish to make threadsafe. The method must block calling threads until the task performed in write is complete. Only 1 thread at a time can...
3
by: cwertman | last post by:
I have a question regarding dynamic properties. I have an Object say Account --Id --Prefix --Fname --Lname --Suffix
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
0
by: pinxi | last post by:
We are seeking to hire a lead programmer to build a dynamic Web-based imaging module which will enable users to upload a digital image or photograph to the site and choose from thousands of...
9
by: pbd22 | last post by:
Hi. This is just a disaster management question. I am using XMLHTTP for the dynamic loading of content in a very crucial area of my web site. Same as an IFrame, but using XMLHTTP and a DIV. I...
0
by: JamesOo | last post by:
I have the code below, but I need to make it searchable in query table, below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only,...
3
by: vainstah | last post by:
Hello Guys and Galls, To start off, I have reached the solution I was looking for, but I would like comments and feedback on the solution I have reached and tips/tricks on making it more elegant....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.