It'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;
You can get the stream from IsolStorage and send it as follows
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); } }
Please note that when downloading a stream you need to use the folder identifier. Since you are creating a folder, you can get this identifier when the creation of the folder is complete. Just register for the PostCompleted event when sending a request for folderData.
Here is 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); }
source share