The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
How to enumerate folders and files in the public folder? RRS feed

Answers

  • Your app doesn't have access to that location by default. You'll need to have the user select the folder in a FolderPicker first to gain access. Once you have the StorageFolder you can enumerate it normally.

    The Files app has permissions that aren't available to general purpose apps.

    Thursday, December 11, 2014 4:41 PM

All replies

  • You can use GetFilesAsynch method of the StorageFolder class available.

    http://msdn.microsoft.com/en-us/library/windows/apps/br227276.aspx

    This will help you to enumerate the files and folders in the public folder


    using Windows.Storage;
    using System.Threading.Tasks;
    using System.Diagnostics; // For writing results to Output window.
    ...
                // Get the app's installation folder.
                StorageFolder appFolder =
                    Windows.ApplicationModel.Package.Current.InstalledLocation;

                // Get the files in the current folder.
                IReadOnlyList <StorageFile> filesInFolder =
                         await appFolder.GetFilesAsync();

                // Iterate over the results and print the list of files
                // to the Visual Studio Output window.
                foreach (StorageFile file in filesInFolder)
                    Debug.WriteLine(file.Name + ", " + file.DateCreated);


    Please mark the replies as answers if they help or unmark if not.

    Wednesday, December 10, 2014 11:53 AM
  • Hi @Sundar Narasiman, thanks for your reply.

    My question is how to enumerate items in this location: C:\Data\Users\Public\ not where the app installed.

    Thanks!

    Thursday, December 11, 2014 2:27 PM
  • Your app doesn't have access to that location by default. You'll need to have the user select the folder in a FolderPicker first to gain access. Once you have the StorageFolder you can enumerate it normally.

    The Files app has permissions that aren't available to general purpose apps.

    Thursday, December 11, 2014 4:41 PM
  • You can use the KnownFolders interface (but access is restricted to some folders):
    http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.knownfolders.aspx
    Use the standard StorageFolder and StorageFile API to enumerate items and navigate through the directory.

    You must set access capabilities for the folders you want to access (PicturesLibrary, VideoLibrary, etc). Open Package.appxmanifest.xml in your project and look under the Capabilities tab.

    Thursday, December 11, 2014 8:29 PM
  • Thanks @Rob Caplan, I think you are right!
    Friday, December 12, 2014 2:46 AM