I have created an application which populates a .csv file on the data-grid.When the user
clicks a button a dialog box opens and the user selects a .csv file and opens it.

The connection string that I've used is;
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source='"+filename+"'ExtendedProperties=text;HDR=Yes;FMT=Delimited";

When I run the program the error that I get is:
Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Please help.

Dani AI

Generated

The exception you posted is a .NET security (Code Access Security) denial for file I/O rather than a plain OS file‑ACL error. Running elevated (good check, ) fixes Windows permission problems but does not change the trust level the CLR gives an assembly. As suspected, code launched from network/mapped locations is commonly given partial trust and is a frequent cause of this symptom. The quickest diagnosis is simple: copy the EXE and the CSV to a local folder and run it — if the error disappears, it is a trust/CLR policy issue.

If you must run from a share, grant the share or assembly full trust with the .NET policy tool (caspol.exe), or sign the assembly and grant trust to that strong name. Those are standard fixes but they change machine policy, so apply them only when you understand the security impact. Microsoft documents the policy tool and how to change Code Access Security here: caspol.exe documentation. For more detail on the permission being denied see the FileIOPermission reference: FileIOPermission class.

If the problem remains after testing locally and adjusting trust, post the exact .NET runtime version, how the app is being launched (UNC vs mapped drive vs local), and whether the CSV access is done by managed code or an external provider — that information will narrow down the next steps.

Recommended Answers

All 4 Replies

try to run your application as administrator and feed me back!

try to run your application as administrator and feed me back!

Yes I ran the application as you adviced me to, but it is giving me a new error,
regarding connectionstring what should be the connection string to populate a .csv file
in a datagrid?

You are not by chance trying to run the application from a network share or mapped drive ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.