Save and retrieve multiple xaml files in UWP

asked 2020-01-09T16:50:09.393+00:00
Sam R 1 Reputation point

How can I save and retrieve multiple xaml files (each file has multiple textbox user input data) in UWP

Universal Windows Platform (UWP)
{count} votes

3 answers

Sort by: Most helpful
  1. answered 2020-02-10T22:17:25.417+00:00
    Steve Wood 56 Reputation points

    For security reasons UWP apps cannot open or save a file unless the user selects it...that's what the FilePickers are for. The only exception is your application's local storage folder. You can retrieve a list of files from the folder and present them to the user for them to select:

    Windows.Storage.StorageFolder LocalStorageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
    IReadOnlyList theFileList = await LocalStorageFolder.GetFilesAsync(Windows.Storage.Search.CommonFileQuery.OrderByName);

    An alternative is to group all of the xaml files into one file so the user just needs to select one file to retrieve all of the xaml.
    You say you have 20 text boxes in each of the 20 xaml the user creating those 20 xaml sheets themselves or with another app independent of your application? If so then I suggest that when the user selects a xaml sheet you cache a copy of it in your localfolder and when the user wants to open a xaml sheet you first present a UI containing the list of files from your localstorage plus a button to launch a FilePicker for your app to "consume" a new file.

  2. answered 2020-02-17T08:15:26.067+00:00
    Fay Wang - MSFT 5,121 Reputation points


    ​Welcome to our Microsoft Q&A platform!

    When you click the "save" button, you can convert the lists from App.xaml.cs to Json and save it to the local folder.

    private async void Button_Click(object sender, RoutedEventArgs e)
        string json = Serializer.Serialize(App.lists);
        StorageFolder LocalStorageFolder = ApplicationData.Current.LocalFolder;
        StorageFile file = await LocalStorageFolder.CreateFileAsync("MyData.txt", CreationCollisionOption.OpenIfExists);
        await FileIO.WriteTextAsync(file,json);

    When you click the "open" button, get the Json string from local folder and convert it to the lists.

    private async void Button_Click(object sender, RoutedEventArgs e)
        StorageFolder LocalStorageFolder = ApplicationData.Current.LocalFolder;
        StorageFile file = await LocalStorageFolder.CreateFileAsync("MyData.txt",CreationCollisionOption.OpenIfExists);
        string jsonValue = await FileIO.ReadTextAsync(file);
        if (jsonValue.Length>0) {
            App.lists = Serializer.Deserialize>(jsonValue.ToString());

    In each constructor, create a viewmodel which bound with the textBox and assign a value to it from lists.

    VM = App.lists[index];

    When you navigate to the next page, replace the old viewmodel with the current viewmodel in the lists. Here is a simple sample, you can download and check it.

  3. answered 2020-04-30T12:43:09.503+00:00
    Paul Ryan 316 Reputation points

    I know this was back in Jan/Feb -- so forgive me if you already know
    You can use BROADFILE ACCESS -- gives you complete access You will need to go to setting --> Privacy --> FileS ystem and allow the program access to the filesystem

    add the below to 'Package.appxmanifest ' file

    IgnorableNamespaces="uap mp rescap">
    <rescap:Capability Name="broadFileSystemAccess" />

    No comments