theMAMs
theMAMs

Reputation: 83

How to access a list of all files in resource folder of my project?

I have some .TXT files saved in Resource folder of my project. I want to display a list to user in which all files from resource folder are shown and user can select the file he desires.

Later on i will read the user selected file and show it on screen.

Upvotes: 1

Views: 1829

Answers (2)

SKall
SKall

Reputation: 5234

This gets FileInfo's on all txt files in the resources:

        var fileInfos = NSBundle.GetPathsForResources(".txt", path)
            .Select(a => new FileInfo(a));

Now you have the short name, full name etc to play with:

        foreach (var fileInfo in fileInfos)
        {
            System.Diagnostics.Debug.WriteLine(fileInfo.Name);

            using (var streamReader = new StreamReader(new FileStream(fileInfo.FullName, FileMode.Open)))
            {
                System.Diagnostics.Debug.WriteLine(streamReader.ReadToEnd());
            }
        }

Upvotes: 1

Duncan C
Duncan C

Reputation: 131408

Take a look at the NSBundle function pathsForResourcesOfType:inDirectory: That will give you a list of the paths to all the files in a sub-bundle of a bundle. if you call that method on the main bundle you'll get a list of all the files of a certain type in a sub-directory of the main bundle.

(I have no idea how to make use of these functions from xamarin.)

Upvotes: 2

Related Questions