通过SkyDrive API将文件上传到skydrive [英] Upload file to skydrive through SkyDrive API

查看:216
本文介绍了通过SkyDrive API将文件上传到skydrive的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将文本文件上传到我的云端硬盘,或者至少在SD中创建新的文本文件,并通过Windows 8应用程序中的SkyDrive API编辑它的内容。
我该怎么做?



我试过这样做:

  LiveConnectClient客户端=新的LiveConnectClient(会话); 
var fileData = new Dictionary< string,object>();
fileData.Add(name,new_file.txt);
try
{
LiveOperationResult fileOperationResult = await client.PutAsync(me / skydrive,fileData);
this.infoTextBlock.Text = fileOperationResult.ToString();

catch(LiveConnectException异常)
{
this.infoTextBlock.Text = exception.Message;

$ / code>

但是我得到错误
提供的请求无效。根SkyDrive文件夹不能更新。
如果我写了me / skydrive /之类的东西,我得到
提供的URL无效,请求的路径不被支持。
方法LiveConnectClient.PutAsync允许我只更新现有的属性(但不是它的内容)。

应该如何正确地完成?



顺便说一句 - LCDC上的内容(http://msdn.microsoft.com/en-us/library/live/hh826531.aspx)更新?我问,因为在文档中的某些方法不存在于dll(Fe LiveConnectClient.Upload。只有BackgroundUploadAsync)。

感谢您的帮助,
Micheal

解决方案

关闭,但我写道:我不能使用client.upload方法,因为LiveConnectClient类doesn不包含它。这就是为什么我问网站内容更新。

无论如何 - 我有一个答案:

  //创建一个StorageFile(如果存储在你的ApplicationData中,这是一种方法)
StorageFile file = awaitApplicationData.Current.LocalFolder.GetFileAsync yourfilename.txt);

尝试{
client = new LiveConnectClient(session);
LiveOperationResult operationResult = await client.BackgroundUploadAsync(me / skydrive,file.Name,file,OverwriteOption.Overwrite);

catch(LiveConnectException异常){
//处理异常
}


I try to upload a text file to my skydrive or at least create new text file in SD and edit it's content, through SkyDrive API in my Windows 8 application. How can I do that?

I tried to do something like that:

        LiveConnectClient client = new LiveConnectClient(session);
        var fileData = new Dictionary<string, object>();
        fileData.Add("name", "new_file.txt");
        try
        {
            LiveOperationResult fileOperationResult = await client.PutAsync("me/skydrive", fileData);
            this.infoTextBlock.Text = fileOperationResult.ToString();
        }
        catch (LiveConnectException exception)
        {
            this.infoTextBlock.Text = exception.Message;
        }

but I get error "The provided request is not valid. The root SkyDrive folder cannot be updated." If I write something like "me/skydrive/" I get "The provided URL is not valid. The requested path '' is not supported". Method LiveConnectClient.PutAsync allows me only to update existing properties (but not it's content).

How it should be done properly?

Btw - Is content on LCDC(http://msdn.microsoft.com/en-us/library/live/hh826531.aspx) updated? I'm asking because some methods, which are in documentation, doesn't exist in dlls (f.e. LiveConnectClient.Upload. There's only BackgroundUploadAsync).

Thanks for help in advance, Micheal

解决方案

Close but as I wrote: I can't use client.upload method because LiveConnectClient class doesn't contain it. That's why I asked about site content update.

Anyway - I've got an answer:

//create a StorageFile (here is one way to do that if it is stored in your ApplicationData)
StorageFile file = awaitApplicationData.Current.LocalFolder.GetFileAsync("yourfilename.txt");

try {
   client = new LiveConnectClient(session);
   LiveOperationResult operationResult = await client.BackgroundUploadAsync("me/skydrive", file.Name, file, OverwriteOption.Overwrite);
}
catch (LiveConnectException exception) {
  //handle exception                
}

这篇关于通过SkyDrive API将文件上传到skydrive的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆