locked
Win RT Exception RRS feed

  • Question

  • So here is the scenario. I am developing a photoviewer app in Windows Store Apps. Using FolderPicker I am accessing a folder.  All these thing will work for the folders in AppData, ProjectDirectory, Public Libraries like Pictures, Music and SkyDrive but when I try to access folders from my drives then it generates exception.

    As per my knowledge, all the apps runs in Sandbox mode in Windows 8 and 8.1 so that they can access resources to which they have permission  only..  Win RT i.e. Windows Runtime will act as a broker between Store Apps and Operating System resources. So i want to overcome all these stuff...

    Here is the snap of Exception generated.. Hoping for coordination.. thanking you..

    • Moved by Mike Danes Saturday, December 7, 2013 5:47 PM WinStore specific
    Saturday, December 7, 2013 4:31 PM

Answers

  • No, you are not. You passing the Windows.Storage.Search.CommonFileQuery.OrderByDate option to the GetAsyncMethod. You should call the method without parameters and then do the sorting in memory:

                FolderPicker folderPicker = new FolderPicker();
                folderPicker.SuggestedStartLocation = PickerLocationId.Desktop;
                folderPicker.ViewMode = PickerViewMode.List;
                folderPicker.FileTypeFilter.Add(".txt");
                StorageFolder folder = await folderPicker.PickSingleFolderAsync();
                if (folder != null)
                {
                    StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFolderToken", folder);
                }
    
                IReadOnlyList<StorageFile> files = await folder.GetFilesAsync();
                IOrderedEnumerable<StorageFile> orderedFiles = files.OrderBy(f => f.DateCreated);
                foreach (StorageFile item in orderedFiles)
                {
                    ...
                }


    Sunday, December 8, 2013 3:07 PM

All replies

  • In addition to the default locations, like the app install directory, app data locations, and the Downloads folder, a Windows Store app can access more files and folders by declaring capabilities in the app manifest or by calling a file picker to let the user pick files and folders:

    File access and permissions in Windows Store apps: http://msdn.microsoft.com/en-us/library/windows/apps/hh967755.aspx
    Quickstart: Accessing files with file pickers (Windows Store apps using C#/VB/C++ and XAML): http://msdn.microsoft.com/en-us/library/windows/apps/hh771180.aspx
    App capability declarations (Windows Store apps): http://msdn.microsoft.com/en-us/library/windows/apps/hh464936.aspx

    You should post any questions related to building Windows Store Apps in the appropriate forum: http://social.msdn.microsoft.com/Forums/windowsapps/en-US/home?forum=winappswithcsharp

    Saturday, December 7, 2013 4:46 PM
  • As I am designing PhotoViwer App so it should have capability to access all the folders and drives.

    FilePicker works for any file in any drive but I want to access the whole folder. And declaring folders in App.Manifest will not be the practical solution as I am going to deploy it.. It should work for all the drives and folders on any pc whoever download it...

    Anyway thanks for ur suggestion...

    Saturday, December 7, 2013 5:02 PM
  • As Windows Store Apps are running in a sandboxed environment, there's only a limited set of locations they can access.

    You can use a FolderPicker to access any folder that the user selects but you cannot any access any folder on the drive programmatically without using the FolderPicker class.

    Saturday, December 7, 2013 5:16 PM
  • I am currently using FolderPicker but it gives me permission to access only some folders. Those i have stated in my question. Please go through my question again...

    Saturday, December 7, 2013 5:35 PM
  • You can select any folder, and then get the files without specifying the unsupported query option:

                FolderPicker picker = new FolderPicker();
                picker.FileTypeFilter.Add(".txt");
                StorageFolder folder = await picker.PickSingleFolderAsync();
                IReadOnlyList<StorageFile> files = await folder.GetFilesAsync();
                IOrderedEnumerable<StorageFile> ordered = files.OrderBy(f => f.DateCreated);
                ...

    Saturday, December 7, 2013 6:16 PM
  • private async void Button_Click(object sender, RoutedEventArgs e)
            {
                tb1.Visibility = Visibility.Collapsed;
                FolderPicker folderPicker = new FolderPicker();
                folderPicker.SuggestedStartLocation = PickerLocationId.Desktop;
                folderPicker.ViewMode = PickerViewMode.List;
                folderPicker.FileTypeFilter.Add(".jpg");
                StorageFolder folder = await folderPicker.PickSingleFolderAsync();
                if (folder != null)
                {
                    StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFolderToken", folder);
                }

                IReadOnlyList<StorageFile> files = await folder.GetFilesAsync(Windows.Storage.Search.CommonFileQuery.OrderByDate);
                foreach (StorageFile item in files)
                {

                    if (Path.GetExtension(item.Name).Equals(".jpeg") || Path.GetExtension(item.Name).Equals(".jpg"))
                    {
                       using (IRandomAccessStream fileStream = await item.OpenAsync(Windows.Storage.FileAccessMode.Read))
                        {

                            BitmapImage bitmapImage = new BitmapImage();
                            await bitmapImage.SetSourceAsync(fileStream);
                            gridView.Items.Add(bitmapImage);
                            imgData.allImages.Add(bitmapImage);
                        }

                    }

                }

            }

    I am also doing the same thing.. still it doesn't work...

                                               
    Saturday, December 7, 2013 6:27 PM
  • No, you are not. You passing the Windows.Storage.Search.CommonFileQuery.OrderByDate option to the GetAsyncMethod. You should call the method without parameters and then do the sorting in memory:

                FolderPicker folderPicker = new FolderPicker();
                folderPicker.SuggestedStartLocation = PickerLocationId.Desktop;
                folderPicker.ViewMode = PickerViewMode.List;
                folderPicker.FileTypeFilter.Add(".txt");
                StorageFolder folder = await folderPicker.PickSingleFolderAsync();
                if (folder != null)
                {
                    StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFolderToken", folder);
                }
    
                IReadOnlyList<StorageFile> files = await folder.GetFilesAsync();
                IOrderedEnumerable<StorageFile> orderedFiles = files.OrderBy(f => f.DateCreated);
                foreach (StorageFile item in orderedFiles)
                {
                    ...
                }


    Sunday, December 8, 2013 3:07 PM