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

问题描述

我尝试通过 Windows 8 应用程序中的 SkyDrive API 将文本文件上传到我的 skydrive 或至少在 SD 中创建新文本文件并编辑其内容.我该怎么做?

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?

我试图做这样的事情:

        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;
        }

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

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).

应该怎么做才合适?

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

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

推荐答案

关闭,但正如我所写:我不能使用 client.upload 方法,因为 LiveConnectClient 类不包含它.这就是我询问网站内容更新的原因.

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 05:48