0

I get this exceptions when i am trying to create a file inside a folder in sdCard. The folder is created, the file is created, but the text is not written. Someone know why? Because after I will need to access it. This is my code:

StorageFolder myFolder = await KnownFolders.PicturesLibrary.CreateFolderAsync("MarketApp", CreationCollisionOption.ReplaceExisting);
        StorageFile myFile = await myFolder.CreateFileAsync("Products.txt", CreationCollisionOption.ReplaceExisting);
        Stream f = await myFile.OpenStreamForWriteAsync();
        using (StreamWriter sw = new StreamWriter(f))
        {
            sw.WriteLine("Hello world!");
        }

These are the exceptions. They are thrown at the second line.

An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in System.Windows.ni.dll Additional information: Exception has been thrown by the target of an invocation.

Mihai
  • 39
  • 1
  • 10
  • Try changing line `Stream f = await myFile.OpenStreamForWriteAsync();` to `using (Stream f = await myFile.OpenStreamForWriteAsync())`. – Romasz Mar 13 '16 at 11:42
  • I tried before and it doesn't work. Another ideas please! – Mihai Mar 13 '16 at 13:15

0 Answers0