【问题标题】:C# UWP Read from dragged fileC# UWP 从拖动的文件中读取
【发布时间】:2021-03-19 21:31:25
【问题描述】:

我有个小问题:

我试图从拖放的文件中读取文本,但我无法访问该文件。 我真的不知道我做错了什么。 有没有办法获得对文件的访问权限?

我的代码:

if (e.DataView.Contains(StandardDataFormats.StorageItems))
{
    var items = await e.DataView.GetStorageItemsAsync();
    if (items.Count > 0)
    {
        foreach (var appFile in items.OfType<StorageFile>())
        {
            string text = await Windows.Storage.FileIO.ReadTextAsync(appFile);
        }
    }
}

【问题讨论】:

标签: c# uwp drag-and-drop


【解决方案1】:

这个应该可以工作。

if (e.DataView.Contains(StandardDataFormats.StorageItems))
{
    foreach (IStorageItem TargetStorageItem in await DroppedDataInfo.GetStorageItemsAsync())
    {
        if(TargetStorageItem is StorageFile)
        {
            string text = await Windows.Storage.FileIO.ReadTextAsync(TargetStorageItem as StorageFile);
            //Read only this first one in this case...
            break;
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-02
    • 2012-05-15
    相关资源
    最近更新 更多