Reputation: 15599
As part of some code logic, the component downloads the user uploaded files to a specific directory.
I am using
System.IO.File.Delete(file1);
System.IO.File.Delete(file2);
to delete the files. I don't think the local system account IUSR account has permissions to do that.
What are the best practices to handle deletion of files in ASP.NET?
Upvotes: 0
Views: 2359
Reputation: 11
Delete the file before saving it will refresh automatically
System.IO.File.Delete(filepath); fupedit.SaveAs(Server.MapPath(filePath));
Upvotes: 1
Reputation: 15350
I run asp.net sites using Impersonation and authenticate under a trusted domain account user. Then give that user write permissions on the folder that contains the files you want to delete.
Upvotes: 0
Reputation: 14196
Upvotes: 5
Reputation: 63126
if you need to delete the file, the ASP.NET process account (NETWORK SERVICE when on Server 2003 and Vista) must be granted the proper permissions to remove files.
I typically will have a "processing" folder that way I can grant proper permissions just to that directory.
Upvotes: 0