Returned value is null when downloading a file from OneDrive

392 Views Asked by At

As it is said in the documentation, I try to download a file way:

try
{
    LiveDownloadOperation operation = await connectClient.CreateBackgroundDownloadAsync(filePath);
    var result = await operation.StartAsync();
    var file = result.File; // It is null

}
catch
{
    // Handle errors.
}

But result.File is null. I think something is wrong with my file path, which is like this:

path = "file.8c8ce076ca27823f.8C8CE076CA27823F!129"

also tried: path = "file.8c8ce076ca27823f.8C8CE076CA27823F!129/content"

what is the wrong? it is a windows runtime app, using LiveSDK 5.6

1

There are 1 best solutions below

0
On

To read the file content, use the file ID + /content and then access the stream.

example:

LiveConnectClient liveClient = new LiveConnectClient(liveSession);
LiveDownloadOperation operation = 
         await liveClient.CreateBackgroundDownloadAsync(fileId + "/content");
var operationResult = await operation.StartAsync();

var fileContent = 
         await CustomMethod(await operationResult.GetRandomAccessStreamAsync());

return fileContent;