Ibraheem Osama Mohamed (ابراهيم اسامه محمد)

Welcome to my blog :)

Windows 8 Future Access List

leave a comment »

One of Windows 8’s amazing feature is FutureAccessList. The idea behind it is once the user picked a certain file using the file picker you can added this file to the future access list and use it later in your application.
You get access to the file using a token , so when you add a file to the future access list you get a token for that file and you can use this token later to get this file.

Another amazing thing is that every application has its own futureAccessList so many apps can share the same file at the same time.

Now let’s try and see how it works.
1)Add new Windows 8 applicaiton from Visual Studio.
2)Add 2 buttons in the MainPage.xaml

<Button Content=”Get File From Token” Name=”GetFileFromTokenButton” HorizontalAlignment=”Left” Margin=”740,224,0,0″ VerticalAlignment=”Top” Click=”GetFileFromTokenButton_Click”/>

<Button Content=”Set token” HorizontalAlignment=”Left” Name=”SetTokenButton” Margin=”927,227,0,0″ VerticalAlignment=”Top” Click=”SetTokenButton_Click”/>

4)Add the event handlers for the events and define a string called token to save the token in it.

string token = null;

        private async void SetTokenButton_Click(object sender, RoutedEventArgs e)

        {

            var op = newFileOpenPicker { FileTypeFilter = { “*” }, CommitButtonText = “select this file”, SuggestedStartLocation = PickerLocationId.Desktop, ViewMode = PickerViewMode.List };

            var file = await op.PickSingleFileAsync();

            if (file != null)

            {

                token = StorageApplicationPermissions.FutureAccessList.Add(file);

            }

        }

        private async void GetFileFromTokenButton_Click(object sender, RoutedEventArgs e)

        {

            if (token != null)

            {

                StorageFile fileFromList = awaitStorageApplicationPermissions.FutureAccessList.GetFileAsync(token);

                await(new Windows.UI.Popups.MessageDialog(fileFromList.DisplayName)).ShowAsync();

            }

        }

Now lets run the application and press the set button

Select a file.

1

Then press the get button a message with a file name pops up as written in our code 🙂

2

For sure the best practice is to save the token in a place you can get back to it later

2056910448_thanks_xlarge

Ibraheem Osama Mohamed
[MVP]
@IbraheemOM

Advertisements

Written by Ibraheem Osama Mohamed

January 13, 2014 at 6:44 pm

Posted in Windows 8, Windows 8.1, xaml

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: