1

I am using Rasp Pi 3 with Win IoT. I am trying to create a .txt file with Data & time as file name. However, it seems that I can't create .txt file.

I am testing out by pressing a button to generate a log.txt file. After pressing the button, there is no error message. When I read the USB drive, the Log folder was created but there is not Log.txt file.

private async void Btn_Click(object sender, RoutedEventArgs e)
    {
        var removableDevices = KnownFolders.RemovableDevices;
        var externalDrives = await removableDevices.GetFoldersAsync();
        var drive0 = externalDrives[0];

        var logFolder = await drive0.CreateFolderAsync("Log");
        var logFile = await logFolder.CreateFileAsync("Log.txt");

        var byteArray = new byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 };
        using (var sourceStream = new MemoryStream(byteArray).AsRandomAccessStream())
        {
            using (var destinationStream = (await logFile.OpenAsync(FileAccessMode.ReadWrite)).GetOutputStreamAt(0))
            {
                await Windows.Storage.Streams.RandomAccessStream.CopyAndCloseAsync(sourceStream, destinationStream);
            }
        }
    }

Thanks.

mylim
  • 313
  • 4
  • 16
  • Have you added File Type Association declarations for .txt in your app manifest? – Rita Han Sep 20 '17 at 02:24
  • I haven't done it.. I just added it.. there are properties & supported file types.. any idea to guide me thru the fill in the blanks? – mylim Sep 20 '17 at 02:58

1 Answers1

4

You need to add File Type Association declarations for .txt in your app manifest like this:

enter image description here

Rita Han
  • 9,574
  • 1
  • 11
  • 24