//********************************************************* // // Copyright (c) Microsoft. All rights reserved. // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. // //********************************************************* using SDKTemplate; using System; using System.IO; using Windows.Storage; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Navigation; namespace FileAccess { /// <summary> /// An empty page that can be used on its own or navigated to within a Frame. /// </summary> public sealed partial class Scenario8 : SDKTemplate.Common.LayoutAwarePage { MainPage rootPage = MainPage.Current; public Scenario8() { this.InitializeComponent(); DeleteFileButton.Click += new RoutedEventHandler(DeleteFileButton_Click); } /// <summary> /// Deletes a file /// </summary> private async void DeleteFileButton_Click(object sender, RoutedEventArgs e) { try { rootPage.ResetScenarioOutput(OutputTextBlock); StorageFile file = rootPage.sampleFile; if (file != null) { string filename = file.Name; await file.DeleteAsync(); rootPage.sampleFile = null; OutputTextBlock.Text = "The file '" + filename + "' was deleted"; } } catch (FileNotFoundException) { rootPage.NotifyUserFileNotExist(); } } } }