This is how I was creating a folder on OneDrive using Windows Phone API.
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;
}
}
But now, I just want to replace a folder name 'OldFolder' on OneDrive to 'NewFolder'. How can I do this using API?
Any help will much be appreciated. Thanks. :-)
Each folder in the OneDrive API is considered to be an "item". And each item can be updated with a new name.
These rows should update the item with id "folderId" and give it the new name "NewFolder".
var Client = new HttpClient();
var request = new HttpRequestMessage(
new HttpMethod("PATCH"),
String.Format("/drive/items/{0}", folderId)
);
var renameInstruction = new StringContent("{\"name\":\"NewFolder\"}");
request.Content = renameInstruction;
var opResult = await Client.SendAsync(request);
Tested on my private OneDrive folder using the OneDrive console .
API source: https://github.com/OneDrive/onedrive-api-docs/blob/master/items/update.md
Let me know if anything is unclear or strange in any way. Have a marvelous day!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.