如何使用Windows Phone API在OneDrive上重命名文件夹?

时间:2015-08-11 04:48:26

标签: c# windows-phone-8 windows-phone onedrive

这就是我使用Windows Phone API在OneDrive上创建文件夹的方式。

    public async Task<string> CreateSkyDriveFolder()
    {
        string folderId = null;
        var opResult = await Client.GetAsync("me/skydrive/files?filter=folders");
        dynamic result = opResult.Result;

        foreach (dynamic folder in result.data)
        {
            if (folder.name.ToLowerInvariant().Trim() == skyDriveFolderName.ToLowerInvariant().Trim())
            {
                folderId = folder.id;
                break;
            }
        }

        if (folderId == null)
        {
            var folderData = new Dictionary<string, object>();
            folderData.Add("name", skyDriveFolderName);
            opResult = await Client.PostAsync("me/skydrive", folderData);
            result = opResult.Result;
            folderId = result.id;
        }
    }

但是现在,我只想更换文件夹名称&#39; OldFolder&#39;在OneDrive上使用NewFolder&#39;。如何使用API​​执行此操作?

任何帮助都将不胜感激。谢谢。 : - )

1 个答案:

答案 0 :(得分:0)

OneDrive API中的每个文件夹都被视为&#34;项目&#34;。 每个项目都可以使用新名称进行更新。

这些行应该使用id&#34; folderId&#34;更新项目。并给它新名称&#34; NewFolder&#34;。

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {

    if editingStyle == UITableViewCellEditingStyle.Delete {
        tableView.beginUpdates()

        titles.removeValueForKey(indexPath.row)
        tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
        tableView.endUpdates()

        var myItem = PFQuery(className: "Items")

        myItem.whereKey("price", containsString: "\(prices)")
        myItem.getFirstObjectInBackgroundWithBlock { (object: PFObject?, error: NSError?) -> Void in

            if error == nil {
                object?.deleteInBackgroundWithBlock({ (success: Bool, error: NSError?) -> Void in
                    if success {
                        tableView.reloadData()
                    }


                })
            }
        }


    }
}

使用OneDrive console在我的私人OneDrive文件夹中测试。

API来源:https://github.com/OneDrive/onedrive-api-docs/blob/master/items/update.md

如果有任何不清楚或有任何异常,请告诉我。有一个美好的一天!