In Visual Studio 2008
I just added the following lines to an existing (working) project:
if (File.Exists(c_szInvoiceFolder + szAttachmentFile))
File.Delete(c_szInvoiceFolder + szAttachmentFile);
if (File.Exists(c_szApp_DataFolder + szTemplateFile))
File.Copy(c_szApp_DataFolder + szTemplateFile, c_szInvoiceFolder + szAttachmentFile);
When the code runs the first time, the file is copied as expected.
However, when the code is re-run, I get “Access to the path … is denied” on the delete line.
According to all the documentation I can find, the ASP.NET development server should run as the logged on user. That seems to not be the case here as I can delete the files myself.
Anyone have any ideas why this is happening?
NOTE: this is happening on my laptop when running in the VS Dev environment.
ANOTHER NOTE: Why would I have permission to CREATE and NOT DELETE?
BTW, I have tried to fix this by granting EVERYONE Full Access to the directory. No help.
Found the issue. The original file was ReadOnly so the copy was ReadOnly. Cleared the ReadOnly flag from the original and all works ok.