I'm making an app that need to write to a txt file for remember some settings in c#. I used that type of code:
class Preferiti
{
public static string[] Read()
{
string path = "Assets/mytxtfile.txt";
using (StreamReader sr = new StreamReader(path))
{
string[] values = sr.ReadToEnd().Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
return values;
}
}
public async static void Write(string mod)
{
string[] try = Read();
bool write = true;
for (var i = 0; i < try.Length; i++)
{
if (try[i] == mod)
{
write = false;
break;
}
}
if (write)
{
string path = "Assets/mytxtfile.txt";
using (StreamWriter outfile = new StreamWriter(path, true))
{
await outfile.WriteLineAsync("" + mod);
MessageBox.Show("Added to list");
}
}
else
{
MessageBox.Show("It exist in the list");
}
}
}
When i try it on debug on my device, it works without any problems, but if i publish it on the store it read with any problems the file, but on the moment of write on it crash and exit form the app.
Can you help me to resolve that type of error?
Thank you very much
I post the image of the correction that you suggest to me... why do that to me?