DeleteAsync() private method

private DeleteAsync ( ) : IAsyncAction
return IAsyncAction
Example #1
0
		public static async Task DeleteFoldersRecursively(StorageFolder folder, string folderName)
		{
			folder = await folder.GetFolderAsync(folderName);
			await folder.DeleteAsync();
		}
Example #2
0
        public static async Task <Windows.Storage.StorageFolder> extractFiles(Windows.Storage.StorageFile zipfilename)
        {
            Windows.Storage.StorageFolder storfolder = null;
            try
            {
                // Create stream for compressed files in memory
                using (MemoryStream zipMemoryStream = new MemoryStream())
                {
                    using (Windows.Storage.Streams.IRandomAccessStream zipStream = await zipfilename.OpenAsync(Windows.Storage.FileAccessMode.Read))
                    {
                        // Read compressed data from file to memory stream
                        using (Stream instream = zipStream.AsStreamForRead())
                        {
                            byte[] buffer = new byte[1024];
                            while (instream.Read(buffer, 0, buffer.Length) > 0)
                            {
                                zipMemoryStream.Write(buffer, 0, buffer.Length);
                            }
                        }
                    }
                    storfolder = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFolderAsync(zipfilename.DisplayName, Windows.Storage.CreationCollisionOption.GenerateUniqueName);

                    // Create zip archive to access compressed files in memory stream
                    using (ZipArchive zipArchive = new ZipArchive(zipMemoryStream, ZipArchiveMode.Read))
                    {
                        // For each compressed file...
                        foreach (ZipArchiveEntry entry in zipArchive.Entries)
                        {
                            // ... read its uncompressed contents
                            using (Stream entryStream = entry.Open())
                            {
                                if (entry.Name != "")
                                {
                                    string fileName = entry.FullName.Replace("/", @"\");
                                    byte[] buffer   = new byte[entry.Length];
                                    entryStream.Read(buffer, 0, buffer.Length);

                                    // Create a file to store the contents
                                    Windows.Storage.StorageFile uncompressedFile = await storfolder.CreateFileAsync(fileName, Windows.Storage.CreationCollisionOption.ReplaceExisting);

                                    // Store the contents
                                    using (Windows.Storage.Streams.IRandomAccessStream uncompressedFileStream = await uncompressedFile.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite))
                                    {
                                        using (Stream outstream = uncompressedFileStream.AsStreamForWrite())
                                        {
                                            outstream.Write(buffer, 0, buffer.Length);
                                            outstream.Flush();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
                if (storfolder != null)
                {
                    await storfolder.DeleteAsync();
                }
                return(null);
            }
            finally
            {
                zipfilename.DeleteAsync();
            }
            return(storfolder);
        }