Solved

Delete File after Download

Posted on 2006-11-30
8
361 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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…
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…

777 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