locked
metro style c# - file path access RRS feed

  • General discussion

  • Hello,

    how to retrive all file's paths in a folder ? iam using vs 2011 express with visual c#.

    Getfiles,DirectoryInfo are not found!


    please

    Tuesday, February 14, 2012 3:39 AM

All replies

  • Hi 333santana333,

    For a Metro style app you'll use the StorageFile and StorageFolder classes. See the File access sample for an example.

    Note that your app will have limited access to the file system system. It can see files in its app data store, but to see user data it will need to declare the access or have the user grant access via a FilePicker or FolderPicker.

    --Rob

    Tuesday, February 14, 2012 6:49 AM
    Moderator
  • Thank you for your response. I don't know how to use Storage File and StorageFolder classes, can you explain with an example? 

    please

    Tuesday, February 14, 2012 7:01 AM
  • As Rob mentioned, you can check the following example - http://code.msdn.microsoft.com/windowsapps/File-access-sample-d723e597 - it demonstrates various scenarios of using StorageFile.
    Tuesday, February 14, 2012 12:28 PM
  • Thankyou for your response. i have already selected the folder which contains files using folder pickerclass and   i just need all paths of files in that folder how can i achive this?

    please

    Tuesday, February 14, 2012 12:40 PM
  • You need to do something like this:

    var files = await folder.GetFilesAsync();

    Tuesday, February 14, 2012 12:54 PM
  • Thank you very much it works!
    but only read one folders file names or path
    i need sub folder's too. please help me this is my code 
    -----------------------------------------------------------
     async void sa_Click(object sender, RoutedEventArgs e)
            {


                FolderPicker folderPicker = new FolderPicker();
                folderPicker.SuggestedStartLocation = PickerLocationId.Desktop;
                folderPicker.FileTypeFilter.Add(".docx");
                folderPicker.FileTypeFilter.Add(".xlsx");
                folderPicker.FileTypeFilter.Add(".pptx");
                folderPicker.FileTypeFilter.Add(".jpeg");
                folderPicker.FileTypeFilter.Add(".jpg");
                StorageFolder folder = await folderPicker.PickSingleFolderAsync();
                 if (null != folder)
                {
                    // Application now has read/write access to all contents in the picked folder (including other sub-folder contents)
                    StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFolderToken", folder);
                    Scenario3FolderName.Text = folder.Name;
                    string argument = folder.Path;
                    dd.Text = argument;
                    var files = await folder.GetFilesAsync();
                    
                        foreach (StorageFile file in files)
                        {
                            jj.Text += file.Path + "\n";
                        }
                   
                }
                else
                {
                    Scenario3FolderName.Text = "Folder was not returned";
                }
            }
    -----------------------------------------------------------------
    now i got all file names in a selected folder i also need sub folder's files
    please help me 

    please

    Wednesday, February 15, 2012 2:22 AM