0

This is really annoying problem and it's going to drive me mad. I like to read information such like files, directories ect. but my app cannot find anything OUTSIDE its folder it runs in.

I'm using Visual Studio 2015 and developing Windows Universal apps.

This routine under works very well if I change the directory inside the folder my app run like "Assets" and any other folder. But outside of my app folder result is zero, not even any errors :-(

Ok, Here is the simple code, What I Do Wrong?

private void GetThem_Click(object sender, RoutedEventArgs e)
{
    string myDir = @"c:\mydir\";
    string[] files;
    files = Directory.GetFiles(myDir,"*.jpg");

    foreach (string stuff in files)
    {
        RESULT.Text = RESULT.Text + stuff + " , ";
    }
}
krlzlx
  • 5,752
  • 14
  • 47
  • 55
Weissu
  • 409
  • 3
  • 15

1 Answers1

-1

A quick search would have given you the answer : It is not possible to access the file system like a classic desktop app. The answer of @Rico Suter explain you what you can acces and how :

  • Directories which are declared in the manifest file (e.g. Documents, Pictures, Videos folder)
  • Directories and files which the user manually selected with the FileOpenPicker or FolderPicker
  • Files from the FutureAccessList or MostRecentlyUsedList
  • Files which are opened with a file extension association or via sharing

Once a file is picked by the user, you can add it to MostRecentlyUsedList or FutureAccessList to use it again later using this snippet (C#) from MSDN :

StorageFile file = await savePicker.PickSaveFileAsync();
if (file != null)
{
   // Add to MRU with metadata (For example, a string that represents the date)
   string mruToken = Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.Add(file, "20120716");

   // Add to FA without metadata
   string faToken = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(file);  
}

Then store the retrieved token because you will need it to access the file using GetFileAsync(token)

Community
  • 1
  • 1
bviale
  • 5,245
  • 3
  • 28
  • 48
  • So, for example, if my files are in drive D: E: or anything like that I cannot access files without "Picker" ? That sounds crazy... (OK, somehow also good idea) Any idea (or quick easy and simple example in net) how to use FutureAccessList? Sounds that it's only way to store folders user has gave access to use.. – Weissu Mar 08 '16 at 11:48
  • Yes that is the point of sandboxed apps, you cannot access files directly. This ensures user data is protected. See my edited answer for the usage of FutureAccessList and MostRecentlyUsedList. – bviale Mar 08 '16 at 12:21
  • Great. I needed to make some small changes to get folder and now it seems to start to work. Thanks for help! – Weissu Mar 08 '16 at 13:37
  • If the answer helped you solving your issue can you consider to mark it as [accepted](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) ? Thanks ! Cheers – bviale Mar 08 '16 at 14:48