Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code never execute 1

Status
Not open for further replies.

abs2003

MIS
Aug 31, 2004
80
US
I have no idea why my code is not executing
Code:
Dim filepath As String = "c"\temp\test.txt"
Dim contentString As String = "attachment; filename=" & """" & filepath & """"

Response.AddHeader("content-disposition", contentString)
Response.WriteFile(filepath)
Response.End()

'this is where it never executed
If File.Exists(filepath) Then
   File.Delete(filepath)
End If
 
I see one thing right off:
Code:
Dim filepath As String = "c"\temp\test.txt"
You're missing a colon character.

Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
chiph,
i know it's typo. Eventhough
Code:
Dim filepath As String = "c\temp\test.txt"
the code execute the download function. It never execute the file.delete function. Any idea?
 
Does the code execute File.Exists convincingly?

__________________________________________
Try forum1391 for lively discussions
 
dimandja,
the code stop right after
Code:
response.end()

What I try to do is let the user download a file. The app will automatically deletes the file from the source location right after user finishes downloading.

Thank you,
 
>The app will automatically deletes the file from the source location right after user finishes downloading.

How do you know the downloading has finished? You cannot delete an open file.

__________________________________________
Try forum1391 for lively discussions
 
Abs2003,

Code:
Response.End()

This End event "sends all currently buffered output to the client, stops execution of the page, and raises the Application_EndRequest event". This means that it won't run any code after that.

For example try running the following code on a blank page:

Code:
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        Response.Write("1")
        Response.End()
        Response.Write("2")
    End Sub

If you step through the code you will notice that it stops at Response.End() and "2" isn't written to the page.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
ca8msm,
You are absolutely right. I don't think it can do what I want it to do then. My intention for it to do is..
On button click, get information form SQL server, write the a temperary file (unique file name such as guid) as text, send it to client's pc, and then delete the temperary file.

Thank you,
 
...send it to client's pc, and then delete the temperary file.

abs2003 - you are exactly right. Without monitoring the number of bytes send to the client pc for each file, there is no way of knowing that the file has been downloaded in it's entirity by the client.

You could of course write a cleanup routine that deleted these files on user login or even the beginning of each hour/day etc.


----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Good idea ca8msm. I thought about writing a window service to clean this folder. More work for me...
 
I thought about writing a window service to clean this folder. More work for me...
I'm afraid so!

Just make sure that when you are cleaning up that you don't delete files that people may be downloading (maybe check for files that are over and hour or so old).

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top