0

I'm new to Xamarin.Mac desktop development.

I'm building a OS X based application and I need to save and retrieve some text data within my app.

I tried the same approach that we use in windows like, create a file and save data into that file and modify or retrieve as you need.

But thing in macOS seems different, My Application is creating file but I can only read data from that file. Permission Issue. (can't write to file without admin rights).

I have tried several approaches, here's one of those approaches (I tried to remove readonly permissions from code while creating it). How to remove a single Attribute (e.g. ReadOnly) from a File?

But result is same.

I wanted to know is there any other approach that can allow my app to read and write data into that?

Edit: Code

string path = Path.Combine(Directory.GetCurrentDirectory(), fileName);
            if (File.Exists(path))
            {
            using (FileStream aFile = new FileStream(path, FileMode.Append, FileAccess.Write))
                {
                    using (StreamWriter sw = new StreamWriter(aFile))
                    {
                        sw.WriteLine(fileData);
                    }
                }
            }
            else
            {
            using (StreamWriter sw = new StreamWriter(path))
                {
                    sw.WriteLine(fileData);
                }



            }
njerry003
  • 1
  • 3

1 Answers1

1

You cannot just write to any path. Try to user documents folder that should work.

var documents = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments); 
var filename = Path.Combine (documents, "Write.txt");
File.WriteAllText(filename, "Write this text into a file");
svn
  • 1,235
  • 10
  • 22