Reputation: 3
I am new to Xamarin. I have VS2017 and have my device (Samsung note4 ) connected tested and it works. But I want to create and write to a file
string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string filename = Path.Combine(path, "myfile.txt");
using (var streamWriter = new StreamWriter(filename, true))
{
streamWriter.WriteLine(DateTime.UtcNow);
}
I run this on the device and no error or anything. debugger is not throwing any error. but when I search for this file on my phone, I can't find it any where at all. did it create a file, and wrote to it? if so, where would that be?
Upvotes: 0
Views: 916
Reputation: 1781
Your code should work, try to read it to make sure where it is; This is how you can do it, for more details please see the xamarin forum post, hope it helps;
string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string filename = Path.Combine(path, "myfile.txt");
using (var streamWriter = new StreamWriter(filename, true))
{
streamWriter.WriteLine(DateTime.UtcNow);
}
using (var streamReader = new StreamReader(filename))
{
string content = streamReader.ReadToEnd();
System.Diagnostics.Debug.WriteLine(content);
}
Upvotes: 1