Reputation: 161
I'm doing a donwload OneDrive txt file with the code:
var downloadOperationResult = await cliente.DownloadAsync(idOfFile);
using (Stream downloadStream = downloadOperationResult.Stream)
{
if (downloadStream != null)
{
//download completed
}
}
And I am using the following code to read the downloaded file (In place of the comment:"//download completed")
using (StreamReader sr = new StreamReader(downloadStream))
{
string text = sr.ReadToEnd();
}
But instead of reading the txt is reading the file properties. Output:
{
"id":"file. + idFile
"from":{
"name":"myname",
"id":the id
},
"name": name of file
"description": ""
"parent_id": id of folder
(...)
Could anyone help me? (I'm developing for Windows Phone)
Upvotes: 0
Views: 1152
Reputation: 21
To get the file content instead of the file meta data, add "/content" to the file ID
file meta data
path = "file.8c8ce076ca27823f.8C8CE076CA27823F!129"
file content
path = "file.8c8ce076ca27823f.8C8CE076CA27823F!129/content"
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;
Upvotes: 1
Reputation: 21
Question was asked a while ago but, someone may find value in the answer. On Windows Phone you will want to handle file downloads Async. This is to handle the case when a user may page away from an application.
You can find more info at http://msdn.microsoft.com/en-US/library/dn659730.aspx
try
{
LiveDownloadOperation operation = await connectClient.CreateBackgroundDownloadAsync(filePath);
var result = await operation.StartAsync();
// Handle result.
}
catch
{
// Handle errors.
}
Upvotes: 0