Search code examples
c#windows-7live-sdkonedrive

How to rename a file/folder on OneDrive using Patch-Request?


I am about to write an App which synchronizes my local folder with the cloud. As far as I know the LiveSDK doesn't provide any method that would help me with that? So after searching on the internet i found an example here : http://onedrive.github.io/items/move.htm It is about moving a file, but there is also a name property which should changeable. So how do I build the Request in C# ?

This is how I tried so far, do not really know how to build the URL, with what parameters and so on. Also, can i make a PATCH-Request with a WebClient?

string url = String.Format("https://apis.live.net/v5.0/" + fileid + "?access_token="+this.liveConnectClient.Session.AccessToken);
using (WebClient wc = new WebClient())
{

//wc.DownloadData(url);

wc.UploadData(url, "PATCH", null);

}

I would be grateful for any clues.


Solution

  • It doesn't look like WebClient can support PATCH requests. You'll likely need to use the HttpWebRequest method (https://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.method.aspx) which supports additional verbs. The console on http://dev.onedrive.com should give you a better understanding of how the requests are put together for different calls.