Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Delete File after Download

Posted on 2006-11-30
8
Medium Priority
?
368 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 15

Assisted Solution

by:Solar_Flare
Solar_Flare earned 700 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 1300 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

636 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