上传到Skydrive的特定文件夹

本文关键字:文件夹 Skydrive | 更新日期: 2023-09-27 18:17:48

所以我知道上传文件到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,然后将文件上传到该位置?

上传到Skydrive的特定文件夹

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)
{
}