I have a c# .Net web page that writes a .csv file into the inetpub\ftproot folder on a Windows 2019 server.
string fileName = @"d:\inetpub\ftproot\competencies.csv";
using (System.IO.TextWriter w = new StreamWriter(fileName, false, Encoding.ASCII))
When I try to create the file, I get an access denied error.
System.UnauthorizedAccessException
HResult=0x80070005
Message=Access to the path 'd:\inetpub\ftproot\competencies.csv' is denied.
I changed the file permissions to "Everyone" with "Full Control" on folder and subfolders to see if permissions were the issue, same error. I changed the connection in IIS basic settings to use an Administrator to see if that would fix it. It didn't. I checked to make sure file didn't already exist. It doesn't.
Finally, I changed the file extension to .txt rather than .csv and it worked! It wrote the text file fine. So, what about the .csv extension would cause the access denied error?
EDIT: Procmon showed the following:
7:38:46.0371899 AM w3wp.exe 23216 CreateFile D:\inetpub\ftproot\Competencies.csv IS DIRECTORY Desired Access: Generic Write, Read Attributes, Disposition: OverwriteIf, Options: Sequential Access, Synchronous IO Non-Alert, Non-Directory File, Open No Recall, Attributes: n/a, ShareMode: Read, AllocationSize: 0
CodePudding user response:
Caius was actually very close to the answer! There were no programs that had the file open but somehow in the initial application creation, I created a hidden file with the same name. When I turned on hidden files, I saw it.