Solved

Delete File after Download

Posted on 2006-11-30
8
362 Views
Last Modified: 2008-02-01
I generate a JPEG from a Graphic, and then download the graphic, using:

Response.Clear()
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", _
  "attachment; filename=""" & varFileName & """")
Response.Flush()
Response.WriteFile(varFilePath & varFileName)

This download works fine.  Now I would like to delete the workfile at varFilePath and varFileName, so I do this:

System.IO.File.Delete(varFilePath & varFileName)

The delete works, except that it causes the "open/save" dialog to not appear, as if it were deleting the file before the
response can get to it.   Take out the delete line, response then works again.

What might I do to automatically delete the work file, ensuring that this occurs after the "open/save" dialog  of the download as been completed or cancelled?

Thanks!

0
Comment
Question by:codequest
8 Comments
 
LVL 15

Assisted Solution

by:Solar_Flare
Solar_Flare earned 175 total points
ID: 18049770
try adding Response.End after you write the file to it.


another thing that you could do is to not save the file to disk. You can probably save the image directly to the response stream without having to put it on disk first.

I am not sure of the syntax, but the image.save method accepts a stream, and if you can save that to the response stream, mayber something like
 
yourimage.Save(response)  or yourimage.Save(response.GetStream)
0
 
LVL 2

Author Comment

by:codequest
ID: 18049791
Thanks for the suggestions.  I'll check those out and postback.
0
 
LVL 5

Accepted Solution

by:
rajups earned 325 total points
ID: 18052303
Hi,

Response.Clear()
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", _
  "attachment; filename=""" & varFileName & """")

Response.WriteFile(varFilePath & varFileName)
Response.Flush()
Response.Close()


If (System.IO.File.Exists(varFilePath & varFileName)) Then
          System.IO.File.Delete(varFilePath & varFileName)
End If

This will work.

All d Best,
Raju P S
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 2

Author Comment

by:codequest
ID: 18060769
Thanks for input.  I'll try it and postback.
0
 
LVL 2

Author Comment

by:codequest
ID: 18155940
Still working my way back to this one....
0
 
LVL 2

Author Comment

by:codequest
ID: 18209768
Still working my way back to this one....
0
 
LVL 2

Author Comment

by:codequest
ID: 18338057
Thanks for your patience on this.  I'm coming back around to needing to write this, so I'll be trying these solutions out soon.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 18461333
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
   Accept: rajups {http:#18052303}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

TheLearnedOne
EE Cleanup Volunteer
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

856 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