473,405 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Delete File after User download

Hi all,

How can I delete the file on the server after the user download it?

For example:

I have file name "123.txt" on a server, I copy it to "ABC.txt", then
allow uer download the "ABC.txt" file, then I try to delete file
"ABC.txt", but I can not do it. I can delete the ABC.txt before I copy
it.

here is my code:

File.Copy(_FilePath_Name, fileOrgName)

'SAVE FILE ON THE CLIENT SIDE
Dim objStream As New ADODB.Stream
Response.Clear()
filePath = Convert.ToString(strFolder + _FileName)
objStream.Open()
objStream.Type = ADODB.StreamTypeEnum.adTypeBinary
objStream.LoadFromFile(filePath)
Response.AddHeader("Content-Disposition", "attachment;
fileName = " & _FileName)
Response.Charset = "UTF-8"
Response.ContentType = "application/octet-stream"
Response.BinaryWrite(objStream.Read)
Response.Flush()
Response.End()
objStream.Close()

File.Delete(filePath) 'It never go here
Nov 20 '05 #1
2 2234
The reason it never gets there, is because you call Response.End. That
means objStream.Close never gets executed either.

"TOI DAY" <nt******@yahoo.com> wrote in message
news:e2**************************@posting.google.c om...
Hi all,

How can I delete the file on the server after the user download it?

For example:

I have file name "123.txt" on a server, I copy it to "ABC.txt", then
allow uer download the "ABC.txt" file, then I try to delete file
"ABC.txt", but I can not do it. I can delete the ABC.txt before I copy
it.

here is my code:

File.Copy(_FilePath_Name, fileOrgName)

'SAVE FILE ON THE CLIENT SIDE
Dim objStream As New ADODB.Stream
Response.Clear()
filePath = Convert.ToString(strFolder + _FileName)
objStream.Open()
objStream.Type = ADODB.StreamTypeEnum.adTypeBinary
objStream.LoadFromFile(filePath)
Response.AddHeader("Content-Disposition", "attachment;
fileName = " & _FileName)
Response.Charset = "UTF-8"
Response.ContentType = "application/octet-stream"
Response.BinaryWrite(objStream.Read)
Response.Flush()
Response.End()
objStream.Close()

File.Delete(filePath) 'It never go here

Nov 20 '05 #2


Do you know how I can get around it.

Thanks

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Smith | last post by:
Hello all, I don't know c# that well and thus need urget help. I have a page that displays files from an access database that has a button to be delet file from database. I need a confirmation...
0
by: karunakar | last post by:
Hi All I am not able to read the class name I want read the particular class name string path = System.Configuration.ConfigurationSettings.AppSettings; string className = path + ".User";...
2
by: Shawn | last post by:
Hi. In my application I'm handling sensitive files. I copy them from a file server and onto the webserver, but I have to delete them again as soon as the user is finished with his download. Is...
1
by: Roy | last post by:
Hi, I have a problem that I have been working with for a while. I need to be able from server side (asp.net) to detect that the file i'm streaming down to the client is saved...
2
by: Mark | last post by:
Here is what I am hoping to accomplish: 1. Connect to FTP server - I can do this. 2. Download file contained in the directory that I connect to. 3. Delete file contained on the ftp server. 4. ...
4
by: Ignoramus6539 | last post by:
There were some strange requests to my server asking for config.php file (which I do not have in the requested location). I did some investigation. Seems to be a virus written in perl,...
0
by: ravirajdanasekaran | last post by:
I have written a web form which downloads files to the client automatically. After the download completes, I would like to delete the file that was downloaded. I can't tell how to wait until the...
2
by: SCPOS | last post by:
Cannot delete X: It is being used by another person or program. Close any programs that might be using the file and try again. Of course I have tried closing any programs I know of that may be...
107
by: bonneylake | last post by:
Hey Everyone, Well for the last few days i been trying to figure out how to delete attachments and download attachments to my computer. The deleting is sort of working and i don't know where to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.