/// <summary> /// Deletes the current file. /// </summary> /// <returns></returns> public Task DeleteAsync() { #if WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE return(_file.DeleteAsync().AsTask()); #else return(DeleteAsync(StorageDeleteOption.Default)); #endif }
public async static void RemoveLog() { if (LogFile != null) { await LogFile.DeleteAsync(); } }
public async void When_DeleteFile() { var _folder = Windows.Storage.ApplicationData.Current.LocalFolder; Assert.IsNotNull(_folder, "cannot get LocalFolder - error outside tested method"); Windows.Storage.StorageFile _file = null; try { _file = await _folder.CreateFileAsync(_filename, Windows.Storage.CreationCollisionOption.FailIfExists); Assert.IsNotNull(_file, "cannot create file - error outside tested method"); } catch { Assert.Fail("CreateFile exception - error outside tested method"); } // try delete file try { await _file.DeleteAsync(); } catch { Assert.Fail("DeleteAsync exception - error in tested method"); } // check if method works var _fileAfter = await _folder.TryGetItemAsync("test-deletingfile.txt"); Assert.IsNull(_fileAfter, "file is not deleted - tested method fails"); }
private async Task deleteConfig() { Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder; try { Windows.Storage.StorageFile sampleFile = await storageFolder.GetFileAsync("mensa.json"); await sampleFile.DeleteAsync(); sampleFile = await storageFolder.GetFileAsync("exams.json"); await sampleFile.DeleteAsync(); sampleFile = await storageFolder.GetFileAsync("settings.json"); await sampleFile.DeleteAsync(); } catch (FileNotFoundException ex) { } }
private async Task <Windows.Storage.StorageFile> ReencodePhotoAsync( Windows.Storage.StorageFile tempStorageFile, Windows.Storage.FileProperties.PhotoOrientation photoRotation) { Windows.Storage.Streams.IRandomAccessStream inputStream = null; Windows.Storage.Streams.IRandomAccessStream outputStream = null; Windows.Storage.StorageFile photoStorage = null; try { inputStream = await tempStorageFile.OpenAsync(Windows.Storage.FileAccessMode.Read); var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(inputStream); photoStorage = await Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync(PHOTO_FILE_NAME, Windows.Storage.CreationCollisionOption.GenerateUniqueName); outputStream = await photoStorage.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite); outputStream.Size = 0; var encoder = await Windows.Graphics.Imaging.BitmapEncoder.CreateForTranscodingAsync(outputStream, decoder); var properties = new Windows.Graphics.Imaging.BitmapPropertySet(); properties.Add("System.Photo.Orientation", new Windows.Graphics.Imaging.BitmapTypedValue(photoRotation, Windows.Foundation.PropertyType.UInt16)); await encoder.BitmapProperties.SetPropertiesAsync(properties); await encoder.FlushAsync(); } finally { if (inputStream != null) { inputStream.Dispose(); } if (outputStream != null) { outputStream.Dispose(); } var asyncAction = tempStorageFile.DeleteAsync(Windows.Storage.StorageDeleteOption.PermanentDelete); } return(photoStorage); }
/// <summary> /// Remove a file /// </summary> public static async System.Threading.Tasks.Task <bool> RemoveFile(string path) { try { Windows.Storage.StorageFile file = await Windows.Storage.StorageFile.GetFileFromPathAsync(path); if (file != null) { await file.DeleteAsync(); } } catch (Exception Ex) { System.Diagnostics.Debug.WriteLine("Exception while removing file: " + Ex.Message); } return(false); }
public static async void CheckLocalConnections(Boolean newSession) { List <Device> devices = await GetConnectedDevices(); Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalCacheFolder; Windows.Storage.StorageFile cacheFile = await storageFolder.CreateFileAsync("devices.xml", Windows.Storage.CreationCollisionOption.OpenIfExists); if (newSession) { await cacheFile.DeleteAsync(); } else { await Task.Delay(1000); } }
public async Task deleteAsync() { if (!deleted) { deleted = true; } else { return; } string file_name = _pageID.ToString() + page_file_name; Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder; Windows.Storage.StorageFile file = await storageFolder.CreateFileAsync(file_name, Windows.Storage.CreationCollisionOption.ReplaceExisting); await file.DeleteAsync(); return; }
private async void btnLogOut_Click(object sender, RoutedEventArgs e) { var Logout = await UserWorkation.InstaApi.LogoutAsync(); if (Logout.Succeeded) { // Delete file. Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder; Windows.Storage.StorageFile File = await storageFolder.GetFileAsync(UserWorkation.User + ".txt"); await File.DeleteAsync(); localSettings.Values["ihaveaaccount"] = "no"; localSettings.Values["LastUser"] = ""; AppShell.framer.Navigate(typeof(LoginPage)); } else { Notinfer.Show("Error: " + Logout.Info.Message, 2000); } }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> async protected override void OnLaunched(LaunchActivatedEventArgs e) { Baza b = new Baza(); if (b.CreateDb()) { Skrbnik s1 = new Skrbnik("Ime", "Priimek", "031111222", 1234); // ZapolniBazo(); var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings; localSettings.Values["DefaultMelodie"] = defaultMelodie; Baza.AddSkrbnik(s1); } else { Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder; try { Windows.Storage.StorageFile novo = await storageFolder.GetFileAsync("SQLITEV3.sqlite"); Windows.Storage.StorageFile staro = await storageFolder.GetFileAsync("SQLITEV2.sqlite"); if (novo != null) { await staro.DeleteAsync(); await novo.RenameAsync("SQLITEV2.sqlite"); } } catch (Exception) { } await UploadDB(); } #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { this.DebugSettings.EnableFrameRateCounter = true; } #endif Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; rootFrame.Navigated += OnNavigated; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: Load state from previously suspended application } // Place the frame in the current Window Window.Current.Content = rootFrame; SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested; SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = rootFrame.CanGoBack ? AppViewBackButtonVisibility.Visible : AppViewBackButtonVisibility.Collapsed; } if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter rootFrame.Navigate(typeof(MainPage), e.Arguments); } // Ensure the current window is active Window.Current.Activate(); }