Search code examples
androidonedrivelive-sdk

create Directory in Onedrive using android


Hi I am using Microsoft liveSDK for android in may application. I am using follwing method for folder creation.

LiveOperation postAsync(String path, JSONObject body, LiveOperationListener listener)

I need to create directory(folder structure) in Onedrive .I have absoute path(eg: A/B/C).If A/B is already exist, I want to create folder C inside folder B(dont want to Overwirte). Have any method is available for this purpose

thanks


Solution

  • The LiveSDK does not support creating a folders path hierarchy. You'd need to create a folder, get its id, and then create the tree of sub-folders under that path.

    There is a OneDrive API that does support this functionality, https://dev.onedrive.com/, which allows for both path based lookup, and path hierarchy creation.

    To create a folder craft a request like the following, in this example we will create the folder hierarchy a > b > c > d > e in a single request.

    POST https://api.onedrive.com/v1.0/drive/root:/a/b/c/d:/children
    Content-Type: application/json
    
    {
        "name":"e",
        "folder":{}
    }