I have a C# .Net 4.0 Project which needs to read text files and parse them - very simple.
The files are located in C:\Testing\Docs
When I try to open a text file in the above directory I get the following error:
Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
The files permissions are set to full access and I am running as administrator.
Is there any way around it?
Thanks.
If you're deploying a ClickOnce application, then the error appears because you don't have the appropriate trust level required to view files. This is different from file permissions.
You can solve this in one of the following ways:
Add the following attribute to your program:
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
Change the trust level in your project properties. The short way is to just check "This is a full trust application", or you can go ahead and add the file permissions manually.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With