【问题标题】:DownloadAsync result file is nullDownloadAsync 结果文件为空
【发布时间】:2015-01-12 15:37:12
【问题描述】:

我使用 Live SDK 5.6 并尝试从 OneDrive 下载文件。使用CreateBackgroundDownloadAsync (innerItem.ID + "/Content"),为什么结果文件为空?

foreach (var innerItem in resultItems.data)
{
    if (innerItem.name == "MoneyNote.db")
    {
        LiveDownloadOperation operation = await liveConnectClient.CreateBackgroundDownloadAsync(innerItem.id + "/Content");
        //LiveDownloadOperationResult downloadResult = await operation.StartAsync();
        var downloadResult = await operation.StartAsync();
        if (downloadResult.File != null)
        {
            StorageFile downFile = await ApplicationData.Current.LocalFolder.GetFileAsync("MoneyNote.db");
            await downloadResult.File.MoveAndReplaceAsync(downFile);
            messagePrint(true);
        }
        else
        {
            messagePrint(false);
        }
    }
}

【问题讨论】:

    标签: c# windows-phone-8.1 async-await live-sdk


    【解决方案1】:

    我认为问题可能是,因为您正在创建后台下载(不是在后台下载),然后您开始此下载操作,但文件需要时间下载。在这种情况下,下载这样的文件可能更容易:

    foreach (var innerItem in resultItems.data)
    {
        if (innerItem.name == "MoneyNote.db")
        {
            StorageFile downFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("MoneyNote.db", CreationCollisionOption.ReplaceExisting);
            var result = await liveConnectClient.BackgroundDownloadAsync(innerItem.id + "/content", downFile);
            messagePrint(true);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2014-09-17
      • 2017-09-27
      • 2016-08-25
      • 2018-12-27
      • 2020-03-27
      • 2013-05-19
      • 2022-01-03
      • 1970-01-01
      • 2019-02-09
      相关资源
      最近更新 更多