Web Server CleanUp Question

Posted on 2012-03-23
Last Modified: 2012-03-26
This may sound like the dumbest question...but I'm NEW to Web Developement and

I've recently begun creating PDF using iTextSharp and if I write to the server and then use Window.Open to display it after the user does what ever they want with it (save, print, etc.) how do I get rid of it on the server so these files don't keep building up?

I tried to display the PDF using Window.Open and then delete the file on page unload but it appears that it deletes it before displaying it, so how do I know when the user is done with the file so I can remove it from the server?


If I create the file using can I open the file automatically instead of displaying the dialog box that gives the user the option to Open, Save or Cancel?  I wouldn't mind using Response.Write if I could automatically open the file on completion.

Question by:smithmrk
  • 2
  • 2

Accepted Solution

gery128 earned 500 total points
ID: 37757058
You can do one thing, once your user request for a file, before generating the file you should loop through the directory (where you save your file) and delete all files using IO namespace. So after that you generate one file which will be deleted on subsequent request from the users. That will make sure you will have only one file at a time on server.

Or if you want directly transfer file to response it can be done (assuming the user has Adobe Reader or any other PDF reader plugin installed on browser) by adding special lines to headers:
see this links:

Author Comment

ID: 37757428
Your first link (Stackoverflow) doesn't work...but let me review the other one and I'll get back to you.


Expert Comment

ID: 37759061

Author Closing Comment

ID: 37767611
Not sure which way I'm going to go, but thanks for the advice!


Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Reading the Web.Config using IIS 7.5? 4 49
Creating a route in webforms 2 32
edit .asp files 5 32
Generate Unique ID in VB.NET 21 69
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question