首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FilePicker - Cant?

FilePicker - Cant?
EN

Stack Overflow用户
提问于 2022-03-14 23:40:06
回答 1查看 549关注 0票数 0

试着让我的应用程序在iOS上工作-哇!这比我想象的要难得多。

好的,所以我有一个文件选择器。非常简单(下面的代码)。用iOs。打开文件选择器对话框,我可以单击我想要的文件,但是什么都不会发生-直到我点击cancel,然后代码继续运行.(寻址结果!= null)。是空码停止..。https://photos.app.goo.gl/fGD5SPtCqdMYE8AS7

代码语言:javascript
复制
    var customFileType =
    new FilePickerFileType(new Dictionary<DevicePlatform, IEnumerable<string>>
    {
        { DevicePlatform.iOS, new[] { "com.microsoft.word.doc" } }, // or general UTType values
        { DevicePlatform.Android, new[] { "application/doc" } },
        { DevicePlatform.UWP, new[] { ".doc" } },
        { DevicePlatform.Tizen, new[] { "*/*" } },
        { DevicePlatform.macOS, new[] { "doc" } }, // or general UTType values
    });
    string OutupPath;
    var pickResult = await FilePicker.PickAsync(new PickOptions
    {
        FileTypes = customFileType,
        PickerTitle = "Select Doc File"
        
    }) ;
    if (pickResult != null)
    {
        OutupPath = pickResult.FullPath.ToString();
        App.docFilePath = OutupPath;
        LoadingText = pickResult.FileName.ToString();
        DbFileName = LoadingText;
    }
    else { 
        return;
    }

注意-我正在开发Win10 vs 2022。我是iOs的新手。我刚刚启动了我的苹果开发帐户。Android版本和Windows版本的工作完美无缺。

不知道我该去哪里解决这个小故障。

https://photos.app.goo.gl/fGD5SPtCqdMYE8AS7

没有选项的原始代码

代码语言:javascript
复制
private async void Button_Clicked(object sender, EventArgs e)
{
    var pickResult = await FilePicker.PickAsync();
    if (pickResult != null)
    {
        FileLabel.Text = pickResult.FileName.ToString();
    }
    else {
        await DisplayAlert("Alert", "No File Selected", "OK");
    }
}
EN

回答 1

Stack Overflow用户

发布于 2022-03-15 06:38:35

在文件类型中也添加org.openxmlformats.wordprocessingml.document怎么样?

文件的实际类型可能是docx,所以只需尝试一下。

请参阅

https://learn.microsoft.com/en-us/answers/questions/362776/xamarin-file-picker-file-types-for-ios.html

https://stackoverflow.com/a/51592769/8187800

更新(在PickOptions中指定doc类型)

代码语言:javascript
复制
var customFileType =
    new FilePickerFileType(new Dictionary<DevicePlatform, IEnumerable<string>>
    {
        { DevicePlatform.iOS, new[] { "com.microsoft.word.doc","org.openxmlformats.wordprocessingml.document" } }, // or general UTType values
        { DevicePlatform.Android, new[] { "application/doc" } },
        { DevicePlatform.UWP, new[] { ".doc" } },
        { DevicePlatform.Tizen, new[] { "*/*" } },
        { DevicePlatform.macOS, new[] { "doc" } }, // or general UTType values
    });

    var pickResult = await FilePicker.PickAsync(new PickOptions
    {
        FileTypes = customFileType,
        PickerTitle = "Select Doc File"
        
    }) ;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71475399

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档