I create a file named "Products.txt" on sdCard. When I open it first time its name is "Products[1].txt", second time the name is "Products[2].txt", third time again "Product[1].txt" and so on. I don't understand why because I don't have another file with the same name. My big problem is that I want to write in it and every time I write something it creates a new one with the same problem. Someone know why the name is changed and how to solve this problem? Thanks! Code for first writing:
StorageFolder myFolder = await KnownFolders.PicturesLibrary.CreateFolderAsync("MyFolder", CreationCollisionOption.ReplaceExisting);
StorageFile myFile = await myFolder.CreateFileAsync("MyFile.txt", CreationCollisionOption.ReplaceExisting);
Stream f = await myFile.OpenStreamForWriteAsync();
using (StreamWriter sw = new StreamWriter(f))
{
sw.WriteLine("First");
}
Code for other writings:
StorageFolder sf = KnownFolders.PicturesLibrary.GetFolderAsync("MyFolder");
StorageFile f = sf.GetFileAsync("MyFile.txt");
using(Stream s = await f.OpenForWriteAsync())
{
using(StreamWriter sw = new StreamWriter(s, true))
{
sw.WriteLine("Others");
}
}
Just change Stream f = await myFile.OpenStreamForWriteAsync();
with using (Stream f = await myFile.OpenStreamForWriteAsync())
and the problem is solved