Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

List all multimedia files

Hello everyone

I am carrying out a project for the company where they have to upload photographic evidence of certain places, I want to know how I can list all the media files of the device without having to choose them previously (as is done with Xam.Plugin.Media), that is, I need Load them before starting the app.

I have tried to read all the phone folders but I have not been successful, I can only read the ones generated by the app.

Beforehand thank you very much.

Tagged:

Answers

  • JarvanJarvan Member, Xamarin Team Xamurai
    edited September 2019

    Use System.IO.Directory.GetFiles method to get the names of specified files.

    var files = System.IO.Directory.GetFiles(path);
    

    Tutorial:
    https://docs.microsoft.com/en-us/dotnet/api/system.io.directory.getfiles?view=netframework-4.8

  • Good day Jarvan, thank you very much for responding.

    Yes, I tried to get the files through the System.IO library; also through Enviroment.GetPath but it only returns the files that I generate in my application, not those that are stored by other applications on the device.

    I don't know the location where the media files are stored.

    Thank you.

  • JarvanJarvan Member, Xamarin Team Xamurai
    edited September 2019

    To search also media files in subfolders, use parameter SearchOption.A­llDirectories.

    Method:

    public static string[] GetFiles(string path, string searchPattern, SearchOption searchOption);
    

    Tutorial about the method.

    string[] filePaths = Directory.GetFiles(“/storage/emulated/0”, "*.mp4", SearchOption.AllDirectories);
    
Sign In or Register to comment.