.NET desktop app not able to delete files on Windows 10.


Joined
Oct 5, 2018
Messages
9
Reaction score
0
I have a simple app that tries to delete file located at c drive on Windows 10.
But Win10 does not allow to delete file through c# .net code using File.Delete() . Throws error "access is denied".
File creation is allowed but deletion gives exception.
Can anyone help with this?

Thanks in advance.
 
Ad

Advertisements

Joined
Apr 22, 2017
Messages
2,658
Reaction score
310
I have a simple app that tries to delete file located at c drive on Windows 10.
But Win10 does not allow to delete file through c# .net code using File.Delete() . Throws error "access is denied".
File creation is allowed but deletion gives exception.
Can anyone help with this?

Thanks in advance.
Hi testwinten,

it sounds like a permissions issue, right click the file/folder you are trying to delete > Properties > Security and check what the settings are for your user instance!. You may have to edit the settings to suit yourself?:

file properties.JPG


I hope it helps. :):):):)
 
Joined
Oct 5, 2018
Messages
9
Reaction score
0
The file as all the permissions as mentioned by you.

Still not able to delete it.
Sharing the code for your reference.

public MainWindow()


{

InitializeComponent();

string path = "C:\\Temp\\Test.txt";

try


{

// Delete the file if it exists.


if (File.Exists(path))


{

File.SetAttributes(path, FileAttributes.Normal);

File.Delete(path);

}

}

catch (Exception ex)


{

Console.WriteLine(ex.ToString());

}

}

Error I get is:
Access to the path 'C:\Temp\Test.txt' is denied.
 
Ad

Advertisements

Joined
Apr 22, 2017
Messages
2,658
Reaction score
310
Can you manually access the folder where the files are in the MS.Net folder on C: drive?.

ms.net folder.jpg
 
Ad

Advertisements

Joined
Oct 5, 2018
Messages
9
Reaction score
0
One update:
When I try to use "SetAccessControl" method and assign fill access control to file, I get this exception "Attempted to perform an unauthorized operation."
 
Joined
Apr 22, 2017
Messages
2,658
Reaction score
310
And have you tried deleting the files from there? (The MS.net folder): :D

What user account type are you using?, MS or local, guest or admin, what version of W10 do you have?. ;)
 
Joined
Oct 5, 2018
Messages
9
Reaction score
0
I tried deleting text document from there. But getting same error "Access to the path 'C:\Windows\Microsoft.NET\assembly\test.txt' is denied."

Windows 10 version: WINDOWS 10 Enterprise

User account type: local(having local admin rights)
 
Joined
Apr 22, 2017
Messages
2,658
Reaction score
310
Are the file attributes "Read only" ?:

You might need to take out that tick so to speak. :)
file attributes.2.JPG
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top