I am having a problem where I am trying to delete my file but I get an exception.
if (result == \"Success\")
{
if (FileUpload.HasFile)
{
t
According to File.Delete Method...
An UnauthorizedAccessException
means one of 4 things:
The exception that is thrown when the operating system denies access because of an I/O error or a specific type of security error.
I hit the same thing. Check to ensure that the file is NOT HIDDEN.
If you're using BitDefender there's a good chance its Safe Files feature blocked your operation. This is a form of Ransomware protection that comes with some of its more advanced versions.
Make sure to grant your application access in BitDefender and try again.
Some more details can be found in this BitDefender support page.
I too faced the same problem when trying to do this after deployment at server:
dirPath = Server.MapPath(".") + "\\website\\" + strUserName;
if (!Directory.Exists(dirPath))
{
DirectoryInfo DI = Directory.CreateDirectory(dirPath);
}
string filePath = Server.MapPath(".") + "\\Website\\default.aspx";
File.Copy(filePath, dirPath + "\\default.aspx", true);
File.SetAttributes(dirPath + "\\default.aspx", FileAttributes.Normal);
I granted permission in IIS to other group including administrator and my problem got solved.
I had the exact error when deleting a file. It was a Windows Service running under a Service Account which was unable to delete a .pdf document from a Shared Folder even though it had Full Control of the folder.
What worked for me was navigating to the Security tab of the Shared Folder > Advanced > Share > Add.
I then added the service account to the administrators group, applied the changes and the service account was then able to perform all operations on all files within that folder.