I'm trying to save some data in a text file and then read it in macOS app. It works fine when I run it through debugger. But when I try to run it on another machine it gives an error.
"Access denied to path"
here's my code:
if (File.Exists(fileName))
{
using (FileStream aFile = new FileStream(Path.Combine(Directory.GetCurrentDirectory(), fileName), FileMode.Append, FileAccess.Write))//
{
using (StreamWriter sw = new StreamWriter(aFile))
{
sw.WriteLine(fileData);
}
}
}
else
{
using (StreamWriter sw = new StreamWriter(Path.Combine(Directory.GetCurrentDirectory(), fileName)))
{
sw.WriteLine(fileData);
}
}
this code works fine on windows but why I have this error on mac?
I'm searching for a solution for two days. this question seems to be like mine but I'm having problem after creating the solution.
Xamarin IDE Access to the Path is denied
Note: I have run several tests and it seems my app don't have permissions on its own resource file that resides in the same directory.
So, my question is: Is there something wrong with my code (I'm new to macOS) or I need to do something else so that my app can write data to the file without showing that error?
I don't want to have admin rights to write to one file only.