Solved

Delete File after Download

Posted on 2006-11-30
8
359 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

911 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

22 Experts available now in Live!

Get 1:1 Help Now