阅读TXT下载的OneDrive



我正在做一个下载OneDrive txt文件,代码为:

var downloadOperationResult=等待客户端。DownloadAsync(idOfFile);

using (Stream downloadStream = downloadOperationResult.Stream)
{
if (downloadStream != null)
{                        
//download completed
}
}

我正在使用以下代码读取下载的文件(代替注释:"//下载完成")

using (StreamReader sr = new StreamReader(downloadStream))
{
string text = sr.ReadToEnd();
}

但是,与其读取txt,不如读取文件属性。输出:

{
"id":"file. + idFile
"from":{ 
"name":"myname",
"id":the id
},
"name": name of file
"description": ""
"parent_id": id of folder
(...)

有人能帮我吗?(我正在为Windows Phone开发)

要获取文件内容而不是文件元数据,请在文件ID 中添加"/content">

文件元数据

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

文件内容

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

示例:

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;

刚才有人问过这个问题,但有人可能会从答案中找到价值。在Windows Phone上,您将希望以异步方式处理文件下载。这是为了处理用户可能离开应用程序的情况。

您可以在上找到更多信息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.
}

最新更新