2

我正在尝试过滤掉所有不是图像、视频、音频、pdf 和其他文档文件的文件,例如 microsoft。

目前,我的代码中有这个:

var allowedUTIs = new string[] {
            UTType.Image,
            UTType.PDF,
            UTType.Video,
            UTType.Audio,
            UTType.Movie,
            UTTYPE.Text,
            "com.microsoft.word.doc",
            "com.microsoft.excel.xls",
            "com.microsoft.powerpoint.ppt",
            "org.openxmlformats.wordprocessingml.document"
        };

主要关注的是自定义定义的类型。它是否涵盖了所有 microsoft office 文件类型:doc、xls、ppt、docx 等...

是否还有其他我未涵盖的文档类型,例如苹果的特定文档文件。

4

3 回答 3

5
        var allowedUtis = new string[] {
            UTType.UTF8PlainText,
            UTType.PlainText,
            UTType.RTF,
            UTType.PNG,
            UTType.Text,
            UTType.PDF,
            UTType.Image,
            UTType.UTF16PlainText,
            UTType.FileURL,
            "com.microsoft.word.doc",
            "org.openxmlformats.wordprocessingml.document",
            "com.microsoft.powerpoint.​ppt"
            "org.openxmlformats.spreadsheetml.sheet",
            "org.openxmlformats.presentationml.presentation",
            "com.microsoft.excel.xls"
        };

这些是我的 UTTypes,

在此,对于 doc "com.microsoft.word.doc",对于 docx "org.openxmlformats.wordprocessingml.document" 等等。我已经针对所有文件进行了测试。

于 2017-03-23T07:31:05.020 回答
4

或者你可以像这样使用

       var fileTypes = new string[] {
        "public.utf8-plain-text", 
        "public.plain-text", 
        "public.text",
        "public.png", 
        "public.jpeg", 
        "com.microsoft.bmp",           
        "public.composite-content" 
        "com.adobe.pdf",
        "public.image", 
        "public.file-url", 
        "com.microsoft.word.doc",
        "org.openxmlformats.wordprocessingml.document",
        "com.microsoft.powerpoint.​ppt",
        "org.openxmlformats.spreadsheetml.sheet",
        "org.openxmlformats.presentationml.presentation",
        "com.microsoft.excel.xls"
         };
     

https://developer.apple.com/library/archive/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html

编辑

使用 Xamarin 基本要素

    var customFileType = new FilePickerFileType(new Dictionary<DevicePlatform, IEnumerable<string>>
   {
     {              
      DevicePlatform.Android, fileTypes
     },
     {
        DevicePlatform.iOS, fileTypes
     }
   });
       

 var file = await FilePicker.PickAsync(new PickOptions
 {
    PickerTitle = "Please select a file",
    FileTypes = customFileType,
 });
于 2021-01-12T13:00:11.143 回答
2

要允许视频和音频文件,也有一个选项,如果未添加,它将显示该文件但已禁用,您无法选择。

var allowedUTIs = new string[]
{
    UTType.UTF8PlainText,
    UTType.PlainText,
    UTType.RTF,
    UTType.PNG,
    UTType.Text,
    UTType.PDF,
    UTType.Image,
    UTType.UTF16PlainText,
    UTType.FileURL,
    UTType.Spreadsheet,
    UTType.MP3,
    UTType.MPEG4,
    UTType.MPEG4Audio,
    UTType.WaveformAudio,
    UTType.Audio,
    UTType.Video,
    UTType.GIF,
    UTType.BMP,
    "org.openxmlformats.wordprocessingml.document",
    "com.microsoft.powerpoint.​ppt",
    "org.openxmlformats.spreadsheetml.sheet",
    "org.openxmlformats.presentationml.presentation",
    "com.microsoft.excel.xls",
    "com.microsoft.waveform-​audio",
    "com.microsoft.windows-​media-wmv",
    "com.adobe.illustrator.ai-​image"
};

苹果文档:https ://developer.apple.com/library/archive/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html

于 2019-08-07T11:05:12.627 回答