public async Task UploadAsync(string url, IDictionary<string, string> headers, string method, string file) { byte[] data = null; // Get the local folder. var localStorage = IsolatedStorageFile.GetUserStoreForApplication(); using (var fileStream = new IsolatedStorageFileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read, localStorage)) { using (var memStream = new MemoryStream()) { await fileStream.CopyToAsync(memStream); await fileStream.FlushAsync(); await memStream.FlushAsync(); data = memStream.ToArray(); } } await UploadAsync(url, headers, method, data); }
/// <summary> /// Restores the page state if application was tombstoned. /// </summary> private async void RestoreState() { // Load the image which was filtered from isolated app storage. IsolatedStorageFile myStore = IsolatedStorageFile.GetUserStoreForApplication(); try { if (myStore.FileExists(TombstoneImageFile)) { using (var isoFileStream = new IsolatedStorageFileStream( TombstoneImageFile, FileMode.Open, myStore)) { DataContext dataContext = FilterEffects.DataContext.Instance; // Load image asynchronously at application launch await isoFileStream.CopyToAsync(dataContext.FullResolutionStream); Dispatcher.BeginInvoke(() => { CreatePreviewImages(); }); } } } catch { MessageBox.Show("Error while trying to restore temporary image."); } // Remove temporary file from isolated storage try { if (myStore.FileExists(TombstoneImageFile)) { myStore.DeleteFile(TombstoneImageFile); } } catch (IsolatedStorageException /*ex*/) { MessageBox.Show("Error while trying to delete temporary image."); } // Load also the preview index which was last used if (State.ContainsKey("PivotIndex")) { FilterPreviewPivot.SelectedIndex = (int)State[StateIndexKey]; } }