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?
Delete the file before saving it will refresh automatically
System.IO.File.Delete(filepath); fupedit.SaveAs(Server.MapPath(filePath));
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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.