Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
This is my code for access MyFile.txt from sdCard. I want to append text at the end of the file, but I need to use StreamWriter(String, boolean). How to get path for MyFile.txt from Stream stream?
C#
StorageFolder sdCard = (await KnownFolders.RemovableDevices.GetFoldersAsync()).FirstOrDefault();
StorageFolder myFolder = await sdCard.GetFolderAsync("MyFolder");
StorageFile myFile = await myFolder.GetFileAsync("MyFile.txt");
using (Stream stream = await myFile.OpenStreamForWriteAsync())
{
    using (StreamWriter sw = new StreamWriter(stream, true)) //Here is the error because of stream!!!!
    {
        sw.WriteLine("....");
        sw.Close();
    }
}


What I have tried:

I tried to use "D:\MyFolder\MyFile.txt" instead of stream but I don't know if D: will be always the letter for sdCard.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900