-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a127507
commit 7bbe559
Showing
9 changed files
with
159 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
source/Windows.Storage/Windows.Storage.previous.nugetreferenceswitcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Windows.Storage.Streams ../../../nflib-Windows.Storage.Streams/source/Windows.Storage.Streams/Windows.Storage.Streams.nfproj ../packages/nanoFramework.Windows.Storage.Streams.1.0.5-preview-006/lib/Windows.Storage.Streams.dll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Windows.Storage.Streams ../../../nflib-Windows.Storage.Streams/source/Windows.Storage.Streams/Windows.Storage.Streams.nfproj ../../source/packages/nanoFramework.Windows.Storage.Streams.1.0.5-preview-006/lib/Windows.Storage.Streams.dll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// | ||
// Copyright (c) 2019 The nanoFramework project contributors | ||
// See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using System; | ||
using Windows.Storage; | ||
using Windows.Storage.Streams; | ||
|
||
namespace FileAccess | ||
{ | ||
public class Scenario4_WriteAndReadBytesInAFile | ||
{ | ||
public static void Execute() | ||
{ | ||
string textFromFile = null; | ||
|
||
// Get the logical root folder for all removable storage devices | ||
// in nanoFramework the drive letters are fixed, being: | ||
// D: SD Card | ||
// E: USB Mass Storage Device | ||
StorageFolder externalDevices = Windows.Storage.KnownFolders.RemovableDevices; | ||
|
||
// list all removable storage devices | ||
var removableDevices = externalDevices.GetFolders(); | ||
|
||
if (removableDevices.Length > 0) | ||
{ | ||
// create a file | ||
var myFile = removableDevices[0].CreateFile("data-file-with-content.bin", CreationCollisionOption.ReplaceExisting); | ||
|
||
Console.WriteLine($"OK: Successfully created file: {myFile.Path}"); | ||
|
||
string userContent = "this is a string to be saved as binary data"; | ||
|
||
IBuffer writeBuffer = GetBufferFromString(userContent); | ||
FileIO.WriteBuffer(myFile, writeBuffer); | ||
|
||
Console.WriteLine($"The following { writeBuffer.Length } bytes of text were written to '{myFile.Name}':\r\n{ userContent }"); | ||
|
||
IBuffer readBuffer = FileIO.ReadBuffer(myFile); | ||
using (DataReader dataReader = DataReader.FromBuffer(readBuffer)) | ||
{ | ||
string fileContent = dataReader.ReadString(readBuffer.Length); | ||
|
||
Console.WriteLine($"The following {readBuffer.Length} bytes of text were read from '{myFile.Name}':\r\n{ fileContent }"); | ||
} | ||
} | ||
else | ||
{ | ||
// there is no removable device present | ||
Console.WriteLine($"ERROR: Can't create file. There is no removable device present."); | ||
} | ||
} | ||
|
||
private static IBuffer GetBufferFromString(String str) | ||
{ | ||
using (InMemoryRandomAccessStream memoryStream = new InMemoryRandomAccessStream()) | ||
{ | ||
using (DataWriter dataWriter = new DataWriter(memoryStream)) | ||
{ | ||
dataWriter.WriteString(str); | ||
|
||
return dataWriter.DetachBuffer(); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="nanoFramework.CoreLibrary" version="1.1.1" targetFramework="netnanoframework10" /> | ||
<package id="nanoFramework.Windows.Storage.Streams" version="1.0.5-preview-008" targetFramework="netnanoframework10" /> | ||
</packages> |