本文整理汇总了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
}
}
示例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;
}
}
示例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);
}
}
});
}
示例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);
}
}
}
示例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();
}
}
示例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
{
}
}
示例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);
}
}
示例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");
*/
}
示例9: DeleteAsync
public async Task DeleteAsync(StorageFile file)
{
await file.DeleteAsync(StorageDeleteOption.PermanentDelete);
}
示例10: TryDeleteFileAsync
private async Task<bool> TryDeleteFileAsync(StorageFile file)
{
try
{
await file.DeleteAsync();
return true;
}
catch (IsolatedStorageException)
{
return false;
}
}
示例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;
}
示例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();
}
示例13: DeleteFileAsync
public static async Task DeleteFileAsync(StorageFile file)
{
if (file != null)
await file.DeleteAsync();
}
示例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);
}
}
示例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);
}
}