{"id":13798788,"url":"https://github.com/jfversluis/FilePicker-Plugin-for-Xamarin-and-Windows","last_synced_at":"2025-05-13T06:31:36.140Z","repository":{"id":56084337,"uuid":"115562414","full_name":"jfversluis/FilePicker-Plugin-for-Xamarin-and-Windows","owner":"jfversluis","description":"FilePicker Plugin for Xamarin and Windows","archived":true,"fork":false,"pushed_at":"2020-11-26T10:14:26.000Z","size":1987,"stargazers_count":157,"open_issues_count":1,"forks_count":80,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-04-15T12:25:23.210Z","etag":null,"topics":["filepicker","nuget","plugin","xamarin-forms"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jfversluis.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-27T22:28:46.000Z","updated_at":"2025-03-26T13:33:30.000Z","dependencies_parsed_at":"2022-08-15T12:50:41.253Z","dependency_job_id":null,"html_url":"https://github.com/jfversluis/FilePicker-Plugin-for-Xamarin-and-Windows","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jfversluis%2FFilePicker-Plugin-for-Xamarin-and-Windows","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jfversluis%2FFilePicker-Plugin-for-Xamarin-and-Windows/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jfversluis%2FFilePicker-Plugin-for-Xamarin-and-Windows/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jfversluis%2FFilePicker-Plugin-for-Xamarin-and-Windows/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jfversluis","download_url":"https://codeload.github.com/jfversluis/FilePicker-Plugin-for-Xamarin-and-Windows/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253888873,"owners_count":21979522,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["filepicker","nuget","plugin","xamarin-forms"],"created_at":"2024-08-04T00:00:53.556Z","updated_at":"2025-05-13T06:31:35.759Z","avatar_url":"https://github.com/jfversluis.png","language":"C#","funding_links":[],"categories":["IO/Storage"],"sub_categories":[],"readme":"# FilePicker Plugin for Xamarin.Forms\n\nSimple cross-platform plug-in that allows you to pick files and work with them.\n\nThe original project can be found [here](https://github.com/Studyxnet/FilePicker-Plugin-for-Xamarin-and-Windows/), but seems abandoned, this one was forked and further developed.\n\n### The future: [Xamarin.Essentials](https://docs.microsoft.com/xamarin/essentials/)\n\nSince version 1.6.0 the [Xamarin.Essentials](https://github.com/xamarin/Essentials)\nproject also supports file picking! See the [Migration Guide](#migration-guide)\non how to migrate from this plugin to the official Xamarin.Essentials API!\n\n## Build status\n### Stable [![Build status](https://jfversluis.visualstudio.com/FilePicker%20plugin/_apis/build/status/FilePicker%20Plugin)](https://jfversluis.visualstudio.com/FilePicker%20plugin/_build/latest?definitionId=36) [![NuGet version](https://badge.fury.io/nu/Xamarin.Plugin.FilePicker.svg)](https://badge.fury.io/nu/Xamarin.Plugin.FilePicker)\n \nNuGet: [https://www.nuget.org/packages/Xamarin.Plugin.FilePicker/](https://www.nuget.org/packages/Xamarin.Plugin.FilePicker/)\n \n### Development feed (possibly instable)\n\nAdd this as a source to your IDE to find the latest packages: [https://www.myget.org/F/filepicker-plugin/api/v3/index.json](https://www.myget.org/F/filepicker-plugin/api/v3/index.json)\n\n## Setup\n\n* Install into your Xamarin.Android, Xamarin.iOS, Xamarin.Forms, Xamarin.Mac, Xamarin.WPF project and Client projects.\n\n**Platform Support**\n\n| Platform              |Supported| Version |Remarks|\n| ------------------------ | :-: | :------: | :------------------: |\n|Xamarin.iOS Classic       | Yes | iOS 8+   ||\n|Xamarin.iOS Unified       | Yes | iOS 8+   ||\n|Xamarin.Android           | Yes | API 10+  ||\n|Windows Phone Silverlight | No  |          ||\n|Windows Phone RT          | Yes | 8.1+     |Up to package version 1.4.x|\n|Windows Store RT          | Yes | 8.1+     |Up to package version 1.4.x|\n|Windows 10 UWP            | Yes | 10+      ||\n|Xamarin.Mac               | Yes | * 10.12+ ||\n|WPF                       | Yes | N/A      |Using .NET Framework 4.5|\n\n\\* The Xamarin.Mac implementation has only been tested on MacOS 10.12.\n\n### API Usage\n\nCall **CrossFilePicker.Current** from any platform or .NET Standard project to gain access to APIs.\n\n### Example\n\n    try\n    {\n        FileData fileData = await CrossFilePicker.Current.PickFile();\n        if (fileData == null)\n            return; // user canceled file picking\n\n        string fileName = fileData.FileName;\n        string contents = System.Text.Encoding.UTF8.GetString(fileData.DataArray);\n\n        System.Console.WriteLine(\"File name chosen: \" + fileName);\n        System.Console.WriteLine(\"File data: \" + contents);\n    }\n    catch (Exception ex)\n    {\n        System.Console.WriteLine(\"Exception choosing file: \" + ex.ToString());\n    }\n\n### Methods\n\n#### `async Task\u003cFileData\u003e PickFile(string[] allowedTypes = null)`\n\nStarts file picking and returns file data for picked file. File types can be\nspecified in order to limit files that can be selected. Note that this method\nmay throw exceptions that occured during file picking.\n\nNote that on Android it can happen that PickFile() can be called twice. In\nthis case the first PickFile() call will return null as it is effectively\ncancelled.\n\nParameter `allowedTypes`:\nSpecifies one or multiple allowed types. When null, all file types can be\nselected while picking.\n\nOn Android you can specify one or more MIME types, e.g. \"image/png\"; also wild\ncard characters can be used, e.g. \"image/*\".\n\nOn iOS you can specify UTType constants, e.g. UTType.Image.\n\nOn UWP, specify a list of extensions, like this: `\".jpg\", \".png\"`.\n\nOn WPF, specify strings like this: `\"Data type (*.ext)|*.ext\"`, which\ncorresponds how the Windows file open dialog specifies file types.\n\n### Data structures\n\nThe returned `FileData` object contains multiple properties that can be accessed:\n\n    public class FileData\n    {\n        /// When accessed, reads all data from the picked file and returns it.\n        public byte[] DataArray { get; }\n\n        /// Filename of the picked file; doesn't contain any path.\n        public string FileName { get; }\n\n        /// Full file path of the picked file; note that on some platforms the\n        /// file path may not be a real, accessible path but may contain an\n        /// platform specific URI; may also be null.\n        public string FilePath { get; }\n\n        /// Returns a stream to the picked file; this is the most reliable way\n        /// to access the data of the picked file.\n        public Stream GetStream();\n    }\n\nNote that `DataArray` is filled on first access, so be sure to rewind the stream when\nyou access it via GetStream() afterwards.\n\n### **IMPORTANT**\n**Android:**\nThe FilePath property may contain a content URI that starts with `content://`.\nThe plugin tries hard to find out an actual filename, but when it can't, the\nfile can only be accessed using `GetStream()` or `DataArray`. On Android\n`ContentProvider` classes are used to share data between apps. The resource\nthat is accessed may not even be a file, streamed over the internet or loaded\nfrom a database.\n\nThe plugin also tries to get a persistable content URI that can be stored for\nlater access. Be prepared that this may fail, though. Content could have been\nmoved to a different location or could be deleted.\n\nThe `READ_EXTERNAL_STORAGE` permission is automatically added to your Android\napp project. Starting from Android 6.0 (Marshmallow) the user is asked for the\npermission when not granted yet. When the user denies the permission,\n`PickFile()` returns null.\n\nThe `WRITE_EXTERNAL_STORAGE` is required if you call SaveFile() and must be\nadded to your Android app project by yourself.\n\n**iOS:** \nYou need to [Configure iCloud Driver for your app](https://developer.xamarin.com/guides/ios/platform_features/intro_to_cloudkit).\n\n## Migration guide\n\nMigrating the usage of this FilePicker plugin to `Xamarin.Essentials.FilePicker`\nisn't straight-forward. It's similar, though, since the Essentials code\noriginated from this plugin. Here's a little guide on how to do it.\n\n1. If you don't have the Xamarin.Essentials NuGet package installed yet, install\n   it into the Android, iOS and UWP projects. Also install it into your Forms\n   project, if you're calling the FilePicker from there. Be sure to also\n   properly [initialize Essentials](https://docs.microsoft.com/xamarin/essentials/get-started).\n   You can remove the Xamarin.Plugin.FilePicker NuGet package now or afterwards.\n\n2. Rename the namespaces, types and method calls. Replace\n\n       using Plugin.FilePicker;\n       using Plugin.FilePicker.Abstractions;\n\n   with\n\n       using Xamarin.Essentials;\n\n   Replace `await CrossFilePicker.Current.PickFile()` with\n   `await FilePicker.PickAsync()`. Replace `FileData` with `FileResult` (or\n   use the `var` keyword).\n\n3. Use `Xamarin.Essentials.PickOptions` if you specified file types for picking.\n   Replace code like this:\n\n       string[] fileTypes = null;\n       if (Device.RuntimePlatform == Device.Android)\n           fileTypes = new string[] { \"image/png\", \"image/jpeg\" };\n\n       if (Device.RuntimePlatform == Device.iOS)\n           fileTypes = new string[] { \"public.image\" };\n\n       if (Device.RuntimePlatform == Device.UWP)\n           fileTypes = new string[] { \".jpg\", \".png\" };\n\n    with:\n\n       var options = new PickOptions\n       {\n           FileTypes = new FilePickerFileType(\n               new Dictionary\u003cDevicePlatform, IEnumerable\u003cstring\u003e\u003e\n               {\n                   { DevicePlatform.Android, new string[] { \"image/png\", \"image/jpeg\"} },\n                   { DevicePlatform.iOS, new string[] { \"public.image\" } },\n                   { DevicePlatform.UWP, new string[] { \".jpg\", \".png\" } },\n               }),\n           PickerTitle = \"Select a file to import\"\n       };\n\n    If you can't specify a list of MIME types or file extensions, use `null`\n    as the value of the dictionary entry, or else file picking on that platform\n    won't be available:\n\n       { DevicePlatform.Android, null },\n\n    Note also that the `PickerTitle` is a new property, but the title is only\n    shown on Android.\n\n4. Replace usage of `FileData` with `Xamarin.Essentials.FileResult`. The new\n   FileResult structure has some properties and methods named differently. The\n   biggest change is that you should not (and in some cases on Android can't)\n   rely on `FileResult.FullPath` to be a file system filename. Always use\n   `FileResult.OpenStreamAsync()` to get a stream to the picked file. From\n   there you can either read from the stream directly (e.g. using a\n   `StreamReader`), or copy the file into your app folder. This can be done\n   using `Stream.CopyToAsync()` and has the advantage that you do the copying\n   in a background task, and you can specify a `CancellationToken` that can\n   be used to cancel the operation. You could even show a progress dialog to\n   the user that allows cancelling the transfer.\n\n\n## Troubleshooting\n\n### All platforms\n\n**InvalidOperationException \"Only one operation can be active at a time\"**\n\nThis occurs when `PickFile()` is called multiple times and the task being awaited didn't return or\nthrows an exception that wasn't caught. Be sure to catch any exceptions and handle them\nappropriately. See the example code above.\n\n### Android\n\n**Exception \"This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.\"**\n\nThis occurs when you are using the old-style NuGet references (not the PackageReference mechanism)\nand you forgot to add the NuGet package to the Android package. When using PackageReference this\nis not necessary anymore because the bait-and-switch assemblies of FilePicker are correctly\nresolved.\n\n### iOS\n\n**Picked file path is invalid, file doesn't exist**\n\nOn iOS the plugin uses UIDocumentPickerViewController and specifies the mode\nUIDocumentPickerMode.Import. After picking is done, iOS copies the picked file\nto the app's temporary \"Inbox\" folder where it can be accessed. iOS also cleans up the\ntemporary inbox folder regularly. After picking the file you have to either\ncopy the file to another folder, access the data by getting the property\nDataArray or opening a stream to the file by calling GetStream().\n\n## Contributors\n* [jfversluis](https://github.com/jfversluis)\n* [rafaelrmou](https://github.com/rafaelrmou) (original author)\n* [vividos](https://github.com/vividos)\n \nThanks!\n\n## License\n[MIT Licence](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjfversluis%2FFilePicker-Plugin-for-Xamarin-and-Windows","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjfversluis%2FFilePicker-Plugin-for-Xamarin-and-Windows","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjfversluis%2FFilePicker-Plugin-for-Xamarin-and-Windows/lists"}