Solved

Delete File after Download

Posted on 2006-11-30
8
356 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
 
LVL 2

Author Comment

by:codequest
ID: 18060769
Thanks for input.  I'll try it and postback.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now