0

I use Live SDK 5.6 and I'm trying to download file from OneDrive. Using CreateBackgroundDownloadAsync (innerItem.ID + "/Content"), why is result file null?

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);
        }
    }
}
Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38

1 Answers1

0

I think the problem may be, because you are creating background download (not downloading in the background), then you start this download operation, but file needs time to be downloaded. In this case probably easier would be just to download a file like this:

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);
    }
}
Romasz
  • 29,662
  • 13
  • 79
  • 154