That's easy, you can use the liveClient.UploadAsync
method
private void uploadFile(LiveConnectClient liveClient, Stream stream, string folderId, string fileName) {
liveClient.UploadCompleted += onLiveClientUploadCompleted;
liveClient.UploadAsync(folderId, fileName, stream, OverwriteOption.Overwrite);
}
private void onLiveClientUploadCompleted(object sender, LiveOperationCompletedEventArgs args) {
((LiveConnectClient)sender).UploadCompleted -= onLiveClientUploadCompleted;
// notify someone perhaps
// todo: dispose stream
}
You can get a stream from IsolatedStorage and send it like this
public void sendFile(LiveConnectClient liveClient, string fileName, string folderID) {
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()) {
Stream stream = storage.OpenFile(filepath, FileMode.Open);
uploadFile(liveClient, stream, folderID, fileName);
}
}
Note that you need to use the folder ID when uploading the stream. Since you are creating the folder, you can get this ID when the creation of the folder is complete. Simply register for the PostCompleted
event when posting the request for folderData.
Here's an example
private bool hasCheckedExistingFolder = false;
private string storedFolderID;
public void CreateFolder() {
LiveConnectClient liveClient = new LiveConnectClient(session);
// note that you should send a "liveClient.GetAsync("me/skydrive/files");"
// request to fetch the id of the folder if it already exists
if (hasCheckedExistingFolder) {
sendFile(liveClient, fileName, storedFolderID);
return;
}
Dictionary<string, object> folderData = new Dictionary<string, object>();
folderData.Add("name", "Smart GTD Data");
liveClient.PostCompleted += onCreateFolderCompleted;
liveClient.PostAsync("me/skydrive", folderData);
}
private void onCreateFolderCompleted(object sender, LiveOperationCompletedEventArgs e) {
if (e.Result == null) {
if (e.Error != null) {
onError(e.Error);
}
return;
}
hasCheckedExistingFolder = true;
// this is the ID of the created folder
storedFolderID = (string)e.Result["id"];
LiveConnectClient liveClient = (LiveConnectClient)sender;
sendFile(liveClient, fileName, storedFolderID);
}