Access to known folders, using pickers, writing to and reading from files, caching files for future access George Georgiev Telerik Software Academy academy.telerik.com.

Slides:



Advertisements
Similar presentations
Windows Basic and Dynamic Disk Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator Marian Marinov CEO of 1H Ltd.
Advertisements

HTML Forms, GET, POST Methods Tran Anh Tuan Edit from Telerik Academy
Make swiftly iOS development Telerik Academy Telerik Academy Plus.
Amazon S 3, App Engine Blobstore, Google Cloud Storage, Azure Blobs Svetlin Nakov Telerik Software Academy academy.telerik.com.
RPN and Shunting-yard algorithm Ivaylo Kenov Telerik Software Academy academy.telerik.com Technical Assistant
Shortest paths in edge-weighted digraph Krasin Georgiev Technical University of Sofia g.krasin at gmail com Assistant Professor.
Telerik Software Academy Telerik School Academy.
Asynchronous Programming with C# and WinRT
Unleash the Power of JavaScript Tooling Telerik Software Academy End-to-end JavaScript Applications.
Touch and Gestures with Xamarin Forms
Character sequences, C-strings and the C++ String class, Working with Strings Learning & Development Team Telerik Software Academy.
Hybrid or Native?! Doncho Minkov Telerik Software Academy Senior Technical Trainer
Done already for your convenience! Telerik School Academy Unity 2D Game Development.
Processing Sequences of Elements Telerik School Academy C# Fundamentals – Part 1.
With Mocha and Karma Telerik Academy Telerik Software Academy.
C# Fundamentals – Part I
Welcome to the JSON-stores world Telerik Software Academy Databases.
NoSQL Concepts, Redis, MongoDB, CouchDB
The Business Plan and the Business Model Margarita Antonova Volunteer Telerik Academy academy.telerik.com Business System Analyst Telerik Corporation.
What are ADTs, STL Intro, vector, list, queue, stack Learning & Development Team Telerik Software Academy.
Making JavaScript code by template! Learning & Development Team Telerik Software Academy.
Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical Training Who, What, Why?
Processing Matrices and Multidimensional Tables Svetlin Nakov Telerik Software Academy academy.telerik.com Technical Trainer
Learning & Development Telerik Software Academy.
Reading and Writing Text Files Svetlin Nakov Telerik Software Academy academy.telerik.com Technical Trainer
Telerik Software Academy ASP.NET Web Forms.
Classical OOP in JavaScript Classes and stuff Telerik Software Academy
Optimization problems, Greedy Algorithms, Optimal Substructure and Greedy choice Learning & Development Team Telerik Software.
Using Selenium for Mobile Web Testing Powered by KendoUI Telerik QA Academy Atanas Georgiev Senior QA Engineer KendoUI Team.
NoSQL Concepts, Redis, MongoDB, CouchDB Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical Training
New features: classes, generators, iterators, etc. Telerik Academy Plus JavaScript.Next.
Throwing and Catching Exceptions Tran Anh Tuan Edit from Telerik Software Academy
Past, Present and Future Nikolay Kostov Telerik Software Academy academy.telerik.com Team Lead, Senior Developer and Trainer
Loops, Conditional Statements, Functions Tran Anh Tuan Edit from Telerik Academy
Telerik Software Academy ASP.NET Web Forms.
Private/Public fields, Module, Revealing Module Learning & Development Team Telerik Software Academy.
Building Data-Driven ASP.NET Web Forms Apps Telerik Software Academy ASP.NET Web Forms.
Telerik Software Academy End-to-end JavaScript Applications.
Planning and Tracking Software Quality Yordan Dimitrov Telerik Corporation Team Leader, Team Pulse, Team Leader, Team Pulse, Telerik Corporation,
What you need to know Ivaylo Kenov Telerik Corporation Telerik Academy Student.
Data binding concepts, Bindings in WinJS George Georgiev Telerik Software Academy academy.telerik.com Technical Trainer itgeorge.net.
Pavel Kolev Telerik Software Academy Senior.Net Developer and Trainer
Objects, Properties, Primitive and Reference Types Learning & Development Team Telerik Software Academy.
When and How to Refactor? Refactoring Patterns Alexander Vakrilov Telerik Corporation Senior Developer and Team Leader.
Free Training and Job for Software Engineers Svetlin Nakov, PhD Manager Technical Training Telerik Corp. Telerik Software Academy.
Free Training and Job for Software Engineers Svetlin Nakov, PhD Manager Technical Training Telerik Corp. Telerik Software Academy.
Access to known folders, using pickers, writing to and reading from files, caching files for future access George Georgiev Telerik Software Academy academy.telerik.com.
Doing the Canvas the "easy way"! Learning & Development Telerik Software Academy.
.NET Cloud Development Made Easy George Georgiev Telerik Software Academy academy.telerik.com Technical Trainer 1.
Creating and Running Your First C# Program Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical Training
Course Overview Doncho Minkov Telerik Software Academy Technical Trainer
Correctly Formatting the Source Code Nikolay Kostov Telerik Software Academy academy.telerik.com Senior Software Developer and Technical Trainer
Data Types, Primitive Types in C++, Variables – Declaration, Initialization, Scope Telerik Software Academy academy.telerik.com Learning and Development.
The past, the present, the future Learning & Development Team Telerik Software Academy.
Learn to Design Error Steady Code Svetlin Nakov Telerik Software Academy academy.telerik.com Technical Trainer
Connecting, Queries, Best Practices Tran Anh Tuan Edit from Telerik Software Academy
Processing Sequences of Elements Telerik Software Academy C# Fundamentals – Part 2.
Telerik JavaScript Framework Telerik Software Academy Hybrid Mobile Applications.
Building Rock-Solid Software Nikolay Kostov Telerik Software Academy academy.telerik.com Senior Software Developer and Technical Trainer
Telerik Software Academy Databases.
Things start to get serious Telerik Software Academy JavaScript OOP.
Learning & Development Mobile apps for iPhone & iPad.
Processing Matrices and Multidimensional Tables Telerik Software Academy C# Fundamentals – Part 2.
Nikolay Kostov Telerik Software Academy academy.telerik.com Team Lead, Senior Developer and Trainer
Functions and Function Expressions Closures, Function Scope, Nested Functions Telerik Software Academy
Implementing Control Logic in C# Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical trainer
Mocking tools for easier unit testing Telerik Software Academy High Quality Code.
What why and how? Telerik School Academy Unity 2D Game Development.
Windows Security Model Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator
Presentation transcript:

Access to known folders, using pickers, writing to and reading from files, caching files for future access George Georgiev Telerik Software Academy academy.telerik.com Technical Trainer itgeorge.net

2  Store Apps File Access  Capabilities, Prompting for Access  Accessing "Known Folders"  Documents, pictures, etc.  Pickers  Folder Picker  File Open Picker  Reading and writing to a file  File Save Picker  Storing Files in the Access Cache

Restrictions, Capabilities, Prompting for Access

4  Store Apps don't have typical access to files  Only to the per-app virtual file system  Several ways of accessing the file system  Through known folders  Documents, Pictures, Removable Storage, etc.  Need to add capabilities in app manifest  Through file/folder pickers  System-controlled dialogs/prompts to the user  Through other apps  Participating in file picker or share contracts

 WinRT Storage APIs  Provide file pickers & file picker contracts  Provide KnownFolders enumeration  Provide file input/output operations, file/folder creation, renaming, deleting, etc.  Other storage locations and options  Namespace – Windows.Storage 5

Adding capabilities, using the storage API

7  Known folders are typical folders in Windows  Documents library, Music library, etc.  Apps can access them directly  If they define this capability in the app manifest  Adding known folders capabilities  Go to the manifest, under Capabilities  Pick the folder(s) needed for the app  Under declarations, add File Type Associations  Customize for files your app will access in the known folders

 After editing the manifest, use the storage API  E.g. Windows.Storage.KnownFolders.DocumentsLibrary  The API returns a StorageFolder object  Once you have a StorageFolder, you can:  Access file types declared in the manifest  Read, write, rename, delete, etc.  Create any file type  Open & create subfolders 8

Live Demo

Winows.Storage.Pickers

11  Pickers are special views in Store Apps  Controlled and styled by the system  Limited customization options for apps  Button text, file display mode, visible files (by extension), SuggestedStartLocation etc.  Asynchronously pick files/folders  Visualize picking UI for the user  App keeps running as if on-screen  On successful pick, app gets access to picked item  App can store the file for future access  Windows.Storage.Pickers

Introduction to pickers, picking a folder

13  Folder pickers provide UI for picking folders  Result is received asynchronously  PickSingleFolderAsync() returns a promise  Result value is a StorageFolder  like when using Known Folders  Requires a FileTypeFilter to be set  Files listed to the user when navigating  List/array of strings (extensions, e.g. ".txt", "*")  Doesn't require any capability declarations  Except if using Known Folders for SuggestedStartLocation

Live Demo

Opening existing files

16  File Open pickers open existing files  Result is received asynchronously  PickSingleFileAsync()/PickMultipleFilesAsync() return an awaitable IAsyncOperation  Result value is a StorageFile  Read, write, rename, delete, copy, move, properties, thumbnail, etc.  Requires FileTypeFilter (same as in FolderPicker)  Doesn't require any capability declarations  Except if using Known Folders for SuggestedStartLocation

Live Demo

Using Winows.Storage.FileIO

19  Access to file contents happens through Windows.Storage.FileIO  Provides several read and write methods  Reading, writing & appending strings, bytes, etc.  Operations are asynchronous (awaitable)  Read operation get content in success handler  Write operations could skip handling  Except for success/error notification await Windows.Storage.FileIO.WriteTextAsync(file, text); //here you can notify of success/error (wrap in try-catch) var text = await Windows.Storage.FileIO.ReadTextAsync(file); //use text here or notify of error (wrap in try-catch)

Live Demo

Creating files from Apps

22  File Save pickers create or overwrite files  Created file is received asynchronously  PickSaveFileAsync() returns an awaitable  Result value is a StorageFile  Requires FileTypeChoices (key-value pairs)  Key: the user-friendly file type (e.g. "Web Page")  Value: list of strings, possible filename extensions (e.g. [".htm", ".html"])  Doesn't require any capability declarations  Except if using Known Folders for SuggestedStartLocation var textFileTypes = new List (new string[]{".txt"}); picker.FileTypeChoices.Insert("Plain Text", textFileTypes);

Live Demo

Creating files from Apps

25  Apps access files through StorageFile objects  Folders through StorageFolder objects  Apps can't create such objects on their own  E.g. need a file picker to do it  Can't save the URI of a file and access it  Unless file is in AppData  WinRT supports an API which saves StorageFiles and persists them  Called FutureAccessList  Key-value pairs (string token – StorageFile pairs)

 Using futureAccessList  Insert the StorageFile the app will need later  Can place a unique string token (e.g. filename + timestamp, if not, the system randomizes one)  The file can be accessed at any time (even after app has restarted) 26 var accessCache = Windows.Storage.AccessCache; var futureAccessList = accessCache. StorageApplicationPermissions.FutureAccessList; StorageApplicationPermissions.FutureAccessList; futureAccessList.Add(file); var file = await futureAccessList.GetFileAsync(token); //use file here

Live Demo

форум програмиране, форум уеб дизайн курсове и уроци по програмиране, уеб дизайн – безплатно програмиране за деца – безплатни курсове и уроци безплатен SEO курс - оптимизация за търсачки уроци по уеб дизайн, HTML, CSS, JavaScript, Photoshop уроци по програмиране и уеб дизайн за ученици ASP.NET MVC курс – HTML, SQL, C#,.NET, ASP.NET MVC безплатен курс "Разработка на софтуер в cloud среда" BG Coder - онлайн състезателна система - online judge курсове и уроци по програмиране, книги – безплатно от Наков безплатен курс "Качествен програмен код" алго академия – състезателно програмиране, състезания ASP.NET курс - уеб програмиране, бази данни, C#,.NET, ASP.NET курсове и уроци по програмиране – Телерик академия курс мобилни приложения с iPhone, Android, WP7, PhoneGap free C# book, безплатна книга C#, книга Java, книга C# Николай Костов - блог за програмиране

1. Take the PaintRT app you wrote for the Gestures and Responding to Interactions homework and implement a Save file feature and an Open File feature Gestures and Responding to InteractionsGestures and Responding to Interactions  Save the file in your own format, so that all generated objects are loadable  Open files your app created, enabling the user to continue working on them, as if the app wasn't closed – e.g. users should still be able to change the color of an object by double-tapping it  * Bonus (not obligatory): add a feature for exporting drawings as image files (e.g. Bitmap, PNG, etc.)