Created
April 10, 2017 20:54
-
-
Save jonpryor/c8f2b16fd0ecdcb750e8a38aae2f13f7 to your computer and use it in GitHub Desktop.
PCLStorage NuGet use
This file contains hidden or 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
# initial run: | |
I mono-stdout: # jonp: rootFolder=/data/user/0/scratch.furkanerasian_pclstorage/files | |
I mono-stdout: # jonp: file=/data/user/0/scratch.furkanerasian_pclstorage/files/MySubFolder/answer.txt | |
# second run: | |
I mono-stdout: # jonp: rootFolder=/data/user/0/scratch.furkanerasian_pclstorage/files | |
I mono-stdout: # jonp: existing text: | |
I mono-stdout: 42 | |
I mono-stdout: # jonp: file=/data/user/0/scratch.furkanerasian_pclstorage/files/MySubFolder/answer.txt |
This file contains hidden or 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
using System; | |
using Android.App; | |
using Android.Widget; | |
using Android.OS; | |
using System.Threading.Tasks; | |
using PCLStorage; | |
namespace FurkanErasian_PclStorage | |
{ | |
[Activity (Label = "FurkanErasian_PclStorage", MainLauncher = true, Icon = "@mipmap/icon")] | |
public class MainActivity : Activity | |
{ | |
int count = 1; | |
protected override async void OnCreate (Bundle savedInstanceState) | |
{ | |
base.OnCreate (savedInstanceState); | |
// Set our view from the "main" layout resource | |
SetContentView (Resource.Layout.Main); | |
await PCLStorageSample (); | |
// Get our button from the layout resource, | |
// and attach an event to it | |
Button button = FindViewById<Button> (Resource.Id.myButton); | |
button.Click += delegate { button.Text = $"{count++} clicks!"; }; | |
} | |
public async Task PCLStorageSample () | |
{ | |
IFolder rootFolder = FileSystem.Current.LocalStorage; | |
Console.WriteLine ($"# jonp: rootFolder={rootFolder.Path}"); | |
IFolder folder = await rootFolder.CreateFolderAsync ("MySubFolder", | |
CreationCollisionOption.OpenIfExists); | |
if (await folder.CheckExistsAsync ("answer.txt") == ExistenceCheckResult.FileExists) { | |
var existing = await folder.GetFileAsync ("answer.txt"); | |
var curText = await existing.ReadAllTextAsync (); | |
Console.WriteLine ("# jonp: existing text:"); | |
Console.WriteLine (curText); | |
} | |
IFile file = await folder.CreateFileAsync ("answer.txt", | |
CreationCollisionOption.ReplaceExisting); | |
Console.WriteLine ($"# jonp: file={file.Path}"); | |
await file.WriteAllTextAsync ("42"); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment