Exemple #1
0
        async public Task init(int numToLoad)
        {
            page.LoadingTxt.Visibility = Windows.UI.Xaml.Visibility.Visible;
            //Create the collection
            NotepadItem item;

            //Iterate through MRU list
            AccessListEntryView entries = StorageApplicationPermissions.MostRecentlyUsedList.Entries;

            ItemCount = 0;
            foreach (AccessListEntry entry in entries)
            {
                try
                {
                    item = new NotepadItem();

                    StorageFile storageFile = await StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(entry.Token);

                    item.Title = storageFile.DisplayName;
                    item.Token = entry.Token;

                    if (ItemCount < numToLoad && item.Title != "")
                    {
                        Collection.Add(item);
                        ItemCount++;
                    }

                    //item.FileName = storageFile.Path;
                    IRandomAccessStream txtStream = await storageFile.OpenAsync(FileAccessMode.Read);

                    IInputStream readStream = txtStream.GetInputStreamAt(0);

                    DataReader reader         = new DataReader(readStream);
                    uint       numBytesLoaded = await reader.LoadAsync((uint)txtStream.Size);

                    if (numBytesLoaded > 25)
                    {
                        numBytesLoaded = 25;
                    }
                    item.FileName = reader.ReadString(numBytesLoaded) + "...";
                }
                catch
                {
                    //int i = 0;
                }
            }
            page.LoadingTxt.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            page.RefreshGridView();

            //iterate through each of them again to reset the list
            ItemCount = 0;
            AccessListEntryView entries2 = StorageApplicationPermissions.MostRecentlyUsedList.Entries;

            foreach (AccessListEntry entry in entries2)
            {
                try
                {
                    if (ItemCount < numToLoad)
                    {
                        ItemCount++; //need to do this to keep the count the same
                    }
                    StorageFile storageFile = await StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(entry.Token);
                }
                catch { }
            }
        }
        async private void LoadSelectedFile(NotepadItem item)
        {
            StorageFile sampleFile = await StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(item.Token);

            DisplayFile(sampleFile, false, false);
        }