上传到特定文件夹到Skydrive

时间:2013-06-10 13:37:13

标签: c# windows-runtime

所以我知道将文件上传到skydrive的代码是

LiveAuthClient authClient = new LiveAuthClient();
LiveLoginResult authResult = await authClient.LoginAsync(new List<string>() { "wl.basic", "wl.skydrive", "wl.skydrive_update" });
if (authResult.Status == LiveConnectSessionStatus.Connected)
{
    LiveConnectClient meClient = new LiveConnectClient(authResult.Session);

    StorageFolder storageFolder = KnownFolders.DocumentsLibrary;
    StorageFile sampleFile = await storageFolder.CreateFileAsync("sample.txt");
    await Windows.Storage.FileIO.WriteTextAsync(sampleFile, "Sample Content");

    LiveOperationResult result = await meClient.BackgroundUploadAsync("me/skydrive/testFolder", sampleFile.Name, sampleFile, OverwriteOption.Overwrite);
}

和制作文件夹的代码是

LiveAuthClient authClient = new LiveAuthClient();
LiveLoginResult authResult = await authClient.LoginAsync(new List<string>() { "wl.basic", "wl.skydrive", "wl.skydrive_update" });
try
{
    var folderData = new Dictionary<string, object>();
    folderData.Add("name", "Test Folder");
    LiveConnectClient liveClient = new LiveConnectClient(authResult.Session);
    LiveOperationResult operationResult =
        await liveClient.PostAsync("me/skydrive", folderData);
    dynamic result = operationResult.Result;
}
catch (LiveConnectException exception)
{
}

如何从我创建的文件夹中获取文件夹ID,然后将文件上传到该位置?

1 个答案:

答案 0 :(得分:1)

LiveAuthClient authClient = new LiveAuthClient();
LiveLoginResult authResult = await authClient.LoginAsync(new List<string>() { "wl.basic", "wl.skydrive", "wl.skydrive_update" });
try
{
    var folderData = new Dictionary<string, object>();
    folderData.Add("name", "Test Folder");
    LiveConnectClient liveClient = new LiveConnectClient(authResult.Session);
    LiveOperationResult operationResult =
        await liveClient.PostAsync("me/skydrive", folderData);
    dynamic result = operationResult.Result;
    var folderId = result.id;

    /*result is dynamic object, you can get the folder id with id property 
    operationResult.RawResult will return JSON response with some data related to 
    that folder */
}
catch (LiveConnectException exception)
{
}