当前位置: 首页>>代码示例>>C#>>正文


C# StorageFile.DeleteAsync方法代码示例

本文整理汇总了C#中Windows.Storage.StorageFile.DeleteAsync方法的典型用法代码示例。如果您正苦于以下问题:C# StorageFile.DeleteAsync方法的具体用法?C# StorageFile.DeleteAsync怎么用?C# StorageFile.DeleteAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Windows.Storage.StorageFile的用法示例。


在下文中一共展示了StorageFile.DeleteAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DeleteTempFile

 private async Task DeleteTempFile(StorageFile f)
 {
     try
     {
         await f.DeleteAsync();
     }
     catch
     {
         // ignore
     }
 }
开发者ID:Opiumtm,项目名称:DvachBrowser3,代码行数:11,代码来源:App.xaml.cs

示例2: DeleteFileAsync

 public static async Task<bool> DeleteFileAsync(StorageFile file)
 {
     try
     {
         await file.DeleteAsync(StorageDeleteOption.PermanentDelete);
         return true;
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Failed to delete file: " + ex);
         return false;
     }
 }
开发者ID:pingzing,项目名称:Codeco,代码行数:13,代码来源:FileUtilities.cs

示例3: TryToRemoveFile

 /// <summary>
 /// Tries to delete file n times , each try is postponed by 5 seconds.
 /// </summary>
 /// <param name="nRetries"></param>
 /// <param name="file"></param>
 public static void TryToRemoveFile(int nRetries,StorageFile file)
 {
     Task.Run( async () =>
     {
         try
         {
             await file.DeleteAsync(StorageDeleteOption.PermanentDelete);
         }
         catch (Exception)
         {
             if (nRetries > 0)
             {
                 await Task.Delay(TimeSpan.FromSeconds(5));
                 TryToRemoveFile(nRetries - 1,file);
             }            
         }
     });
 }
开发者ID:Mordonus,项目名称:YoutubeDownloader,代码行数:23,代码来源:Utils.cs

示例4: DeserializeFromFileAsync

 public static async Task<Object> DeserializeFromFileAsync(Type objectType, StorageFile file, bool deleteFile = false)
 {
     if (file == null) return null;
     try
     {
         Object obj;
         AppEventSource.Log.Debug("Suspension: Checking file..." + file.Name);
         // Get the input stream for the file
         using (IInputStream inStream = await file.OpenSequentialReadAsync())
         {
             // Deserialize the Session State
             DataContractSerializer serializer = new DataContractSerializer(objectType);
             obj = serializer.ReadObject(inStream.AsStreamForRead());
         }
         AppEventSource.Log.Debug("Suspension: Object loaded from file. " + objectType.ToString());
         // Delete the file
         if (deleteFile)
         {
             await file.DeleteAsync();
             deleteFile = false;
             AppEventSource.Log.Info("Suspension: File deleted. " + file.Name);
         }
         return obj;
     }
     catch (Exception e)
     {
         AppEventSource.Log.Error("Suspension: Error when deserializing object. Exception: " + e.Message);
         MessageDialog messageDialog = new MessageDialog("Error when deserializing App settings: " + file.Name + "\n" 
             + "The PDF file is not affected.\n " + "Details: \n" + e.Message);
         messageDialog.Commands.Add(new UICommand("Reset Settings", null, 0));
         messageDialog.Commands.Add(new UICommand("Ignore", null, 1));
         IUICommand command = await messageDialog.ShowAsync();
         switch ((int)command.Id)
         {
             case 0:
                 // Delete file
                 deleteFile = true;
                 break;
             default:
                 deleteFile = false;
                 break;
         }
         return null;
     }
     finally
     {
         // Delete the file if error occured
         if (deleteFile)
         {
             await file.DeleteAsync();
             AppEventSource.Log.Info("Suspension: File deleted due to error. " + file.Name);
         }
     }
 }
开发者ID:qiuosier,项目名称:Libra,代码行数:54,代码来源:SuspensionManager.cs

示例5: deleteUsedFile

 /// <summary>
 /// This is used to delete the temporary created file
 /// used in the Share charm and other functions.
 /// </summary>
 public async Task deleteUsedFile()
 {
     // Deletes the temporary created file.
     if (imageOriginal.dstPixels != null)
     {
         file = await ApplicationData.Current.LocalFolder.GetFileAsync("temp.jpg");
         await file.DeleteAsync();
     }
 }
开发者ID:ktodorov,项目名称:Editor,代码行数:13,代码来源:MainPage.xaml.cs

示例6: Delete

    public async void Delete(FlipView display)
    {
        try
        {
            collection = new ObservableCollection<Music>();
            display.ItemsSource = Collection;
            file = await ApplicationData.Current.LocalFolder.GetFileAsync(filename);
            await file.DeleteAsync();
        }
        catch
        {

        }
    }
开发者ID:RoguePlanetoid,项目名称:Windows-10-Universal-Windows-Platform,代码行数:14,代码来源:Library.cs

示例7: DeleteSchedule

 private static async Task DeleteSchedule(BusStop stop, StorageFile file, params string[] routes)
 {
     if (routes == null || routes.Length == 0)
     {
         await file.DeleteAsync();
     }
     else
     {
         WeekSchedule baseSchedule = (await LoadSchedule(stop.ID)) ?? new WeekSchedule();
         baseSchedule.RemoveRoutes(routes);
         if (baseSchedule.IsEmpty)
             await DeleteSchedule(stop, file);
         else
             await OverwriteScheduleAsync(baseSchedule, stop);
     }
 }
开发者ID:AlexKven,项目名称:OneAppAway-RTM,代码行数:16,代码来源:FileManager.cs

示例8: DownloadStart

        public async void DownloadStart(Uri source,StorageFile destinationFile)
        {

            try {
                BackgroundDownloader downloader = new BackgroundDownloader();
                DownloadOperation download = downloader.CreateDownload(source, destinationFile);
                DownloadStarted();
                await download.StartAsync();

                Tracker myTracker = EasyTracker.GetTracker();
                int progress = (int)(100 * (download.Progress.BytesReceived / (double)download.Progress.TotalBytesToReceive));
                if (progress >= 100)
                {
                    myTracker.SendEvent("Downloads", "Download Finished using Share Target", "Download Successfull using Share Target", 1);

                    BasicProperties basic = await download.ResultFile.GetBasicPropertiesAsync();
                    string size;
                    double siz = basic.Size;
                    //     ulong mb = ulong.Parse(1000000);
                    if (siz > 1000000)
                    {
                        double s = siz / 1000000;
                        size = s.ToString() + "MB";
                    }
                    else
                    {
                        double s = siz / 1000;

                        size = s.ToString() + "KB";
                    }

                    DatabaseController.AddDownload(destinationFile.Name, download.ResultFile.Path, download.ResultFile.DateCreated.DateTime.ToString(), size);

                    DowloadFinish(destinationFile);




                }
                else

                {

                    BasicProperties basic = await download.ResultFile.GetBasicPropertiesAsync();

                    double siz = basic.Size;
                    if (siz == 0)
                    {
                        await destinationFile.DeleteAsync();
                        myTracker.SendEvent("Downloads", "Download Failed due to Server Error", null, 3);
                        MessageDialog m = new MessageDialog("Server is down. Try again later", "Fatal Error");
                        await m.ShowAsync();
                    }
                }
            }
            catch(Exception ex)
            {
                
                Debug.WriteLine(ex.ToString());
               
            }
            /*
            var authClient = new LiveAuthClient();
            var authResult = await authClient.LoginAsync(new string[] { "wl.skydrive", "wl.skydrive_update" });
            if (authResult.Session == null)
            {
                throw new InvalidOperationException("You need to sign in and give consent to the app.");
            }

            var liveConnectClient = new LiveConnectClient(authResult.Session);

            string skyDriveFolder = await CreateDirectoryAsync(liveConnectClient, "PDF Me - Saved PDFs", "me/skydrive");
        */
        }
开发者ID:mtwn105,项目名称:PDFMe-Windows-10,代码行数:74,代码来源:MainPage.xaml.cs

示例9: DeleteAsync

 public async Task DeleteAsync(StorageFile file)
 {
     await file.DeleteAsync(StorageDeleteOption.PermanentDelete);
 }
开发者ID:stonemonkey,项目名称:WhereAmI,代码行数:4,代码来源:FileManipulator.cs

示例10: TryDeleteFileAsync

        private async Task<bool> TryDeleteFileAsync(StorageFile file)
        {
            try
            {
                await file.DeleteAsync();

                return true;
            }
            catch (IsolatedStorageException)
            {
                return false;
            }
        }
开发者ID:mdabbagh88,项目名称:UniversalImageLoader,代码行数:13,代码来源:IsolatedStorageImageLoader.cs

示例11: SafeFileDelete

        public async static Task<bool> SafeFileDelete(StorageFile file)
        {
            if (file == null)
            {
                return false;
            }

            try
            {
                await file.DeleteAsync();
            }
            catch (FileNotFoundException)
            {
                // Ignore
            }
            catch (Exception)
            {
                var tempPath = GetUndeletedFilesDirectory();
                await WriteFile(Path.Combine(tempPath, string.Format("{0}.txt", Guid.NewGuid())), file.Path);
                return false;
            }
            return true;
        }
开发者ID:hubaishan,项目名称:quran-phone,代码行数:23,代码来源:FileUtils.cs

示例12: ExportTimetable

 internal static async Task ExportTimetable(string exportFileName, StorageFile destinationFile)
 {
     try
     {
         var sourceFile = await (await GetTimetableDirectory()).GetFileAsync(exportFileName);
         await sourceFile.CopyAndReplaceAsync(destinationFile);
         return;
     }
     catch  { }
     await destinationFile.DeleteAsync();
     await new MessageDialog(Strings.TimetableIOExportError, Strings.MessageBoxWarningCaption).ShowAsync();
 }
开发者ID:JulianMH,项目名称:ModernTimetable,代码行数:12,代码来源:TimetableIO.cs

示例13: DeleteFileAsync

		public static async Task DeleteFileAsync(StorageFile file)
		{
			if (file != null)
				await file.DeleteAsync();
		}
开发者ID:0xdeafcafe,项目名称:SnapDotNet,代码行数:5,代码来源:IsolatedStorage.cs

示例14: StartDownload

        public async void StartDownload(StorageFile fileDownload)
        {
            try {
                var fs = await fileDownload.OpenAsync(FileAccessMode.ReadWrite);
                Stream stream = await Response.Content.ReadAsStreamAsync();
                IInputStream inputStream = stream.AsInputStream();
                ulong totalBytesRead = 0;
                while (true)
                {
                    if (CancelTask)
                    {
                        await fileDownload.DeleteAsync(StorageDeleteOption.PermanentDelete);
                        break;
                    }
                    // Read from the web.
                    IBuffer buffer = new Windows.Storage.Streams.Buffer(1024);
                    buffer = await inputStream.ReadAsync(
                        buffer,
                        buffer.Capacity,
                        InputStreamOptions.None);

                    if (buffer.Length == 0)
                    {
                        break;
                    }

                    // Report progress.
                    totalBytesRead += buffer.Length;
                    OnDownloadProgress(totalBytesRead, FileSizeMb);
                    // Write to file.
                    await fs.WriteAsync(buffer);
                }

                inputStream.Dispose();
                fs.Dispose();
                OnDownloadComplete();
            }
            catch (Exception ex)
            {
                OnDownloadCancel(ex.Message);
            }
        }
开发者ID:nekszer,项目名称:DownloadDialog,代码行数:42,代码来源:DownloadHelper.cs

示例15: uploadWithRetry

        /// <summary>
        /// Attempts to upload the given file, and will recursively retry until the MaxRetries limit is reached. 
        /// </summary>
        /// <param name="file">The file to upload. Assumes calling method has sole access to the file. Will delete the file after uploading</param>
        /// <param name="tryNumber">The number of the attempt being made. Should always initially be called with a value of 1</param>
        /// <returns></returns>
        private async Task uploadWithRetry(StorageFile file, int tryNumber = 1)
        {
            HttpResponseMessage response = await oneDriveConnector.UploadFileAsync(file, String.Format("{0}/{1}", App.Controller.XmlSettings.OneDriveFolderPath, DateTime.Now.ToString("yyyy_MM_dd")));
            bool success = await parseResponse(response, tryNumber);
            var events = new Dictionary<string, string>();

            if (success)
            {
                numberUploaded++;
                await file.DeleteAsync();
                this.lastUploadTime = DateTime.Now;
            }
            else if (tryNumber <= MaxTries)
            {
                events.Add("Retrying upload", tryNumber.ToString());
                TelemetryHelper.TrackEvent("FailedToUploadPicture - Next Retry Beginning", events);
                await uploadWithRetry(file, ++tryNumber);
            }
            else
            {
                events.Add("Max upload attempts reached", tryNumber.ToString());
                TelemetryHelper.TrackEvent("FailedToUploadPicture - All Retries failed", events);
            }
        }
开发者ID:BertusV,项目名称:securitysystem,代码行数:30,代码来源:OneDrive.cs


注:本文中的Windows.Storage.StorageFile.DeleteAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。