I want to write a text file in c#... but it is giving error
Access to the path 'C:\Program Files(x86)\Anil\demoSettings.txt' is denied.
- string executableLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
- string FileName = Path.Combine(executableLocation, "demoSettings.txt");
- var permissionSet = new PermissionSet(PermissionState.None);
- var writePermission = new FileIOPermission(FileIOPermissionAccess.Write, FileName);
- permissionSet.AddPermission(writePermission);
- if (permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet))
- {
- using (FileStream fstream = new FileStream(FileName, FileMode.Create))
- using (TextWriter sw = new StreamWriter(fstream))
- {
- sw.WriteLine("Name," + "Anil");
- sw.WriteLine("Code," + "C#");
- }
- }
how to fix this ??? can anyone help me out???

James AxsomPosted Jun 17, 2018, 4:47 PM
Anilananda ChakraborttyPosted May 28, 2018, 10:55 PM
Bhairab DuttPosted May 28, 2018, 10:16 AM
I think when you add the permission to text file then the problem will solved .
Right click on textfile set the permission of Write ,Read etc by Properties .
Hope its help you.
Thanks.
Nitin SontakkePosted May 28, 2018, 8:10 AM
Anilananda ChakraborttyPosted May 28, 2018, 6:40 AM
Ravi SangtaniPosted May 28, 2018, 6:33 AM