private CreateFileQuery ( ) : |
||
return |
private async void ReadAllFiles() { // Get the app's installation folder. Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder; // Get the files in the current folder. StorageFileQueryResult results = storageFolder.CreateFileQuery(); // Iterate over the results and print the list of files // to the Visual Studio Output window. IReadOnlyList <StorageFile> filesInFolder = await results.GetFilesAsync(); foreach (StorageFile item in filesInFolder) { TextBlock tb = new TextBlock(); tb.Text = item.Name; StackPanel sp = new StackPanel(); sp.Tag = item.Name; sp.Orientation = Orientation.Vertical; sp.Tapped += Sp_Tapped; sp.Children.Add(tb); outerWrapper.Children.Add(sp); } }
public async Task Initialize(ICamera camera, IStorage storage) { this.camera = camera; this.storage = storage; var cacheFolder = KnownFolders.PicturesLibrary; this.dropFolder = await cacheFolder.GetFolderAsync("securitysystem-cameradrop"); this.dropFolderWatcher = dropFolder.CreateFileQuery(); var images = await this.dropFolderWatcher.GetFilesAsync(); var orderedImages = images.OrderByDescending(x => x.DateCreated); this.newestImage = orderedImages.FirstOrDefault(); this.dropFolderWatcher.ContentsChanged += DropFolderWatcher_ContentsChanged; this.allJoynBusAttachment = new AllJoynBusAttachment(); this.producer = new SecuritySystemProducer(this.allJoynBusAttachment); this.allJoynBusAttachment.AboutData.DefaultAppName = Package.Current.DisplayName; this.allJoynBusAttachment.AboutData.DefaultDescription = Package.Current.Description; this.allJoynBusAttachment.AboutData.DefaultManufacturer = Package.Current.Id.Publisher; this.allJoynBusAttachment.AboutData.SoftwareVersion = Package.Current.Id.Version.ToString(); this.allJoynBusAttachment.AboutData.IsEnabled = true; this.producer.Service = this; this.producer.Start(); }
public async Task <StorageFile> GetFile(string filename) { StorageFile file = null; // Access variable for the local storage system, where we're going to store the Student records. Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder; // Get the files available from the localFolder Windows.Storage.Search.StorageFileQueryResult fileResults = localFolder.CreateFileQuery(); // Get the list of files from the query against the localFolder var fileList = await fileResults.GetFilesAsync(); // Look for our file in the results. file = fileList.SingleOrDefault(f => f.Name == filename); return(file); }
public static async Task<double> GetFolderSize(StorageFolder folder) { // Query all files in the folder. Make sure to add the CommonFileQuery // So that it goes through all sub-folders as well var folders = folder.CreateFileQuery(CommonFileQuery.OrderByName); // Await the query, then for each file create a new Task which gets the size var fileSizeTasks = (await folders.GetFilesAsync()).Select(async file => (await file.GetBasicPropertiesAsync()).Size); // Wait for all of these tasks to complete. WhenAll thankfully returns each result // as a whole list var sizes = await Task.WhenAll(fileSizeTasks); // Sum all of them up. You have to convert it to a long because Sum does not accept ulong. var folderSize = sizes.Sum(l => (long)l); return folderSize; }
private async void AddFile_Click(object sender, RoutedEventArgs e) { var FileToCreateName = Filename.Text.ToString(); if (FileToCreateName.Length < 3) { ("File name is too short. Min. 3 characters.").Show(); return; } // van-e már ilyen file? Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder; StorageFileQueryResult results = storageFolder.CreateFileQuery(); IReadOnlyList <StorageFile> filesInFolder = await results.GetFilesAsync(); bool van = false; foreach (StorageFile item in filesInFolder) { if (item.Name == FileToCreateName) { van = true; } } if (van) { "Error: there is a file with the same name.".Show(); return; } // Create sample file; replace if exists. // Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder; Windows.Storage.StorageFile sampleFile = await storageFolder.CreateFileAsync(FileToCreateName, Windows.Storage.CreationCollisionOption.ReplaceExisting); ("File created successfully.").Show(); }
private static async Task<IReadOnlyList<StorageFile>> GetMediaFromFolder(StorageFolder folder, CommonFileQuery query) { IReadOnlyList<StorageFile> files = null; StorageFileQueryResult fileQuery; var queryOptions = new QueryOptions(query, new List<string> { ".3g2", ".3gp", ".3gp2", ".3gpp", ".amv", ".asf", ".avi", ".divx", ".drc", ".dv", ".f4v", ".flv", ".gvi", ".gxf", ".ismv", ".iso", ".m1v", ".m2v", ".m2t", ".m2ts", ".m3u8", ".mkv", ".mov", ".mp2", ".mp2v", ".mp4", ".mp4v", ".mpe", ".mpeg", ".mpeg1", ".mpeg2", ".mpeg4", ".mpg", ".mpv2", ".mts", ".mtv", ".mxf", ".mxg", ".nsv", ".nut", ".nuv", ".ogm", ".ogv", ".ogx", ".ps", ".rec", ".rm", ".rmvb", ".tob", ".ts", ".tts", ".vob", ".vro", ".webm", ".wm", ".wmv", ".wtv", ".xesc", }); try { fileQuery = folder.CreateFileQueryWithOptions(queryOptions); files = await fileQuery.GetFilesAsync(); } catch (Exception ex) { Debug.WriteLine("exception listing files"); Debug.WriteLine(ex.ToString()); } // DLNA folders don't support advanced file listings, us a basic file query if (files == null) { fileQuery = folder.CreateFileQuery(CommonFileQuery.OrderByName); files = await fileQuery.GetFilesAsync(); } return files; }