I recently added a new server to our system the other day and it was configured with Microsoft Windows 2003 server. When I put my ASP.Net website onto this new server I started having all sorts of problems with the image upload code. Specifically, I could not delete a file that was uploaded. I kept getting an "Access to the path is denied" error.
I went through all the standard checks making sure that the ASPNet and IUSR_MACHINENAME accounts had full access to the folder where the images were being upload. Made sure the file didn't have read only permissions. I tested various ways of saving the images via the HtmlInputFile's PostedFile.SaveAs function and using the HTTPFileCollection as well. I tried deleting with System.IO.File.Delete and FileSystemObject. Nothing. That file was stuck there and was refusing to be deleted.
I searched all over the net trying to find the solution to the problem and there were quite a few people out there who have posted similar problems. Most of the time people were recommending that the ASPNet user have write permissions. But I had already checked that a dozen times.
Finally I just started giving full control access to all the users listed in the security tab. Upon giving the Users group full control access I was finally able to delete the files! YEA! But what user in this group was the key users. So I asked a co worker about this and we started comparing user permissions with one of his personal sites where he was uploading users. Bingo, there it was. The IIS_WPG user the culprit.
So I changed my permissions around returning them to normal, added the IIS_WPG user to that folder and gave him full control. Alas, all was well in the world again.
I was really surprised how I did not stumble upon this fix while searching the net. So, now that I spent half a day trying to solve this problem I'm sharing my solution with you and hope it will help save you from many frustrating hours trying to debug this problem.