DownloadAsync 结果文件为空
DownloadAsync result file is null
我使用 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);
}
}
}
我觉得可能是这个问题,因为你是在创建后台下载(不是在后台下载),然后你开始这个下载操作,但是文件需要时间来下载。在这种情况下,下载这样的文件可能更容易:
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);
}
}
我使用 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);
}
}
}
我觉得可能是这个问题,因为你是在创建后台下载(不是在后台下载),然后你开始这个下载操作,但是文件需要时间来下载。在这种情况下,下载这样的文件可能更容易:
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);
}
}