filepicker for text files code example

Haviv Elbsz 2,071 Reputation points
2022-12-14T14:07:26.66+00:00

Hi all

the maui Doc show code for filepicker
for images types

and I need a cofe for text types example

thank you very much

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,487 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,914 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 42,431 Reputation points Microsoft Vendor
    2022-12-15T06:05:13.527+00:00

    Hello,

    You could refer to the following code and documentation to make your text file picker:

       var customFileType = new FilePickerFileType(  
                       new Dictionary<DevicePlatform, IEnumerable<string>>  
                       {  
                           { DevicePlatform.iOS, new[] { "public.text" } }, // UTType values  
                           { DevicePlatform.Android, new[] { "text/plain" } }, // MIME type  
                           { DevicePlatform.WinUI, new[] { ".txt" } }, // file extension  
                           { DevicePlatform.macOS, new[] { "txt" } },   
                       });  
         
       PickOptions options = new()  
       {  
           PickerTitle = "Please select a txt file",  
           FileTypes = customFileType,  
       };  
       var file = FilePicker.PickAsync(options);  
    

    For desktop platfroms, you could use file extension as your file picker types.

    For Android, you need to use MIME type to set the file type, you could refer to this google source code to get more details about the file types corresponding to the MIME types: MimeUtils.java.

    For iOS, you need to use UTI(Uniform Type Identifiers) to do it, please refer to this official comparison table: System-Declared Uniform Type Identifiers.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.