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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting file after File.Copy 1

Status
Not open for further replies.

crazyboybert

Programmer
Jun 27, 2001
798
0
0
GB
Hi All

Ok, my application lets users browse a directory of files on the server and select files to add to the system (write to a specific storage client and the database). When the user selcts a file it is copied into a directory which temporarily stores the file(s) to be added until the user commits. The user can choose to remove files from those already selected on a subsequent postback. Problem is when ASPNET tries to delete the copy of the file from the temporary storage directory it throws the old "Access the the path ... is denied".

Before anyone asks, yes, ASPNET has full control on both the folders in question with inheritable permissions set to propogate.

There is something odd going on though. The users canalso upload files from their local machine to the server from the same form and these are also stored in the same temporary directory. Yet when one of these is deleted there is no problem.

Code to copy and delete is:
Code:
System.File.IO.Copy(source, destination);

and

System.File.IO.Delete(destination);
The file defintitely exists and isnt locked by IIS or such like either. Scratching me head on this one. Anybody got any ideas?

Cheers

Rob

i'm a boy, called Bert, and I may not be crazy, but if i'm not the rest of you are...
 
>> file from the temporary storage directory it throws

is this temporary file common for all users? is there a chance of one user overwriting another user's files???

Known is handfull, Unknown is worldfull
 
What version of Windows are you using?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Try using File.Move instead as it will take care of removing the source file itself and if both files are on the same drive it is much more efficient as all it does is change a directory entry.




Bob Boffin
 
Wow - great to see in my recent abscence that the tek-tips community is just as active and helpful as always, keep upi the good work guys :)

Bizarrely it is now working fine having gone for the conventional coffee and smoke break without me touching the code at all. I'm inclined to think it is developer error [blush] but the bug was definitely there :S

Anyways in answer to your questions in case it reappears..

vbkris: The directory is shared across users but each file that goes in there has a unique identifier as part of the filename that is held in the users session so only they can cause a delete on their files.

ca8msm: XP but we'll go live on 2003. why?

bboffin: The source directory is a shared dumping ground for bulk uploads to the server and as all users can see all files there the management of out of date files etc is handled by a seperate service which is part of the storage system.

Anyway, seems coffee fixed this one on its own ;-) but thanks anyway.

Rob

i'm a boy, called Bert, and I may not be crazy, but if i'm not the rest of you are...
 
Just wondering, as if it was Windows 2003 I was going to point out that you would have to set the permissions for the Network Service account rather than the ASPNET account.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Ah ok - fairy nuff :D

i'm a boy, called Bert, and I may not be crazy, but if i'm not the rest of you are...
 
Found the problem just in case someone else has the same friday no-brain syndrome that I seem to have suffered from!

You can't delete ReadOnly files from the file system programatically regardless of what permissions the ASPNET account has on the file. So you need to use
Code:
System.IO.File.SetAttributes(path, FileAttribuites.Normal);
before calling delete to ensure the file isn't ReadOnly.

DOH!

i'm a boy, called Bert, and I may not be crazy, but if i'm not the rest of you are...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top