CreateFileQueryWithOptions() public method

public CreateFileQueryWithOptions ( [ queryOptions ) : StorageFileQueryResult
queryOptions [
return Windows.Storage.Search.StorageFileQueryResult
		private async void BrowseButton_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				var folderPicker = new FolderPicker()
				{
					CommitButtonText = "Open",
					SuggestedStartLocation = PickerLocationId.DocumentsLibrary,
					ViewMode = PickerViewMode.List
				};
				folderPicker.FileTypeFilter.Add(".shp");

				_folder = await folderPicker.PickSingleFolderAsync();
				if (_folder != null)
				{
					var qopts = new QueryOptions(CommonFileQuery.OrderByName, new string[] { ".shp" });
					var query = _folder.CreateFileQueryWithOptions(qopts);
					var files = await query.GetFilesAsync();
					FileListCombo.ItemsSource = files;
					FileListCombo.Visibility = (files.Any()) ? Visibility.Visible : Visibility.Collapsed;
				}
			}
			catch (Exception ex)
			{
				var _ = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
			}
		}
Example #2
0
        private async void GetAllVideos(StorageFolder KnownFolders, QueryOptions QueryOptions)
        {
            StorageFileQueryResult query = KnownFolders.CreateFileQueryWithOptions(QueryOptions);
            IReadOnlyList<StorageFile> folderList = await query.GetFilesAsync();

            // Get all the videos in the folder past in parameter
            int id = 0;
            foreach (StorageFile file in folderList)
            {
                using (StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(ThumbnailMode.VideosView, 200, ThumbnailOptions.UseCurrentScale))
                {
                    // Get video's properties
                    VideoProperties videoProperties = await file.Properties.GetVideoPropertiesAsync();

                    BitmapImage VideoCover = new BitmapImage();
                    VideoCover.SetSource(thumbnail);

                    Video video = new Video();
                    video.Id = id;
                    video.Name = file.Name;
                    video.DateCreated = file.DateCreated.UtcDateTime;
                    video.FileType = file.FileType;
                    video.VideoPath = file.Path;
                    video.Duration = videoProperties.Duration;
                    video.VideoFile = file;
                    video.VideoCover = VideoCover;

                    // Add the video to the ObservableCollection
                    Videos.Add(video);
                    id++;
                }
            }
        }
        public static async Task<List<StorageFile>> LoadFolderFiles(StorageFolder storageFolder)
        {
            var queryOptions = new QueryOptions
                       (
                       CommonFileQuery.OrderByName, new List<string> { ".3g2", ".3gp2", ".3gp", ".3gpp", ".m4a", ".m4v", ".mp4v", ".mp4", ".mov", ".m2ts", ".asf", ".wm", ".vob", ".wmv", ".wma", ".aac", ".adt", ".mp3", ".wav", ".avi", ".ac3", ".ec3" }
                       );

            var fileQuery = storageFolder.CreateFileQueryWithOptions(queryOptions);

            var ass = await fileQuery.GetFilesAsync();

            return ass.ToList();
        }
Example #4
0
        private async Task<ulong> GetFolderSize(StorageFolder folder) {
            StorageFileQueryResult query = folder.CreateFileQueryWithOptions(new QueryOptions {
                FolderDepth = FolderDepth.Deep
            });

            IReadOnlyList<StorageFile> files = await query.GetFilesAsync();
            ulong size = 0;
            foreach (StorageFile file in files) {
                BasicProperties props = await file.GetBasicPropertiesAsync();
                size += props.Size;
            }

            return size;
        }
        //Allows user to select a folder and load all the music files in it, the files get copied to Assets/Music for future use
        public async void AddMediaFolder()
        {
            var folderPicker = new Windows.Storage.Pickers.FolderPicker();
            folderPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Desktop;
            folderPicker.FileTypeFilter.Add("*");

            Windows.Storage.StorageFolder folder = await folderPicker.PickSingleFolderAsync();
            if (folder != null)
            {
                // Application now has read/write access to all contents in the picked folder
                // (including other sub-folder contents)
                Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFolderToken", folder);
                Debug.WriteLine("Selected folder: " + folder.Name);

                //Filter types of files
                List<string> fileTypeFilter = new List<string>();
                fileTypeFilter.Add(".mp3");
                fileTypeFilter.Add(".mp3");
                fileTypeFilter.Add(".wma");
                fileTypeFilter.Add(".wav");
                fileTypeFilter.Add(".ogg");
                fileTypeFilter.Add(".flac");
                fileTypeFilter.Add(".aiff");
                fileTypeFilter.Add(".aac");

                //Get all the files from the folder
                QueryOptions queryOptions = new QueryOptions(CommonFileQuery.OrderByName, fileTypeFilter);
                StorageFileQueryResult results = folder.CreateFileQueryWithOptions(queryOptions);
                IReadOnlyList<StorageFile> sortedFiles = await results.GetFilesAsync();

                //Get a handle on Assets/Music
                StorageFolder assets = await Package.Current.InstalledLocation.GetFolderAsync(@"Assets\Music");

                //Loop over every file in sortedFiles and add to song collection as well as copy the files to Assets/Music for future use
                foreach (StorageFile file in sortedFiles)
                {
                    songs.Add(new Song { name = file.Name, dateCreated = file.DateCreated.ToString(), fileType = file.FileType, path = file.Path, folder = "Assets/Music" });
                    await file.CopyAsync(assets);
                }

                //Clear the list and reload the new list
                songs.Clear();
                await loadSongs();
            }
            else
            {
                Debug.WriteLine("Empty folder");
            }
        }
 /// <param name="filter">".jpg"</param>
 public async Task<List<Models.ImageInfo>> ThumbnailsAsync(StorageFolder folder, uint requestedSize = 190, params string[] filter)
 {
     var options = new QueryOptions(CommonFileQuery.OrderByName, filter);
     var query = folder.CreateFileQueryWithOptions(options);
     var files = (await query.GetFilesAsync() as IReadOnlyList<StorageFile>).ToList();
     var scale = ThumbnailOptions.UseCurrentScale;
     var mode = ThumbnailMode.PicturesView;
     var result = new List<Models.ImageInfo>();
     foreach (var file in files)
     {
         var thumbnail = await file.GetThumbnailAsync(mode, requestedSize, scale);
         result.Add(new Models.ImageInfo { File = file, Thumbnail = thumbnail });
     }
     return result;
 }
 // Set functionality for the folder
 public async Task SetFolder(StorageFolder folder)
 {
     //unhook the old contents changed event if applicable
     if (_queryResult != null)
     {
         _queryResult.ContentsChanged -= QueryResult_ContentsChanged;
     }
     // Initialize the query and register for changes
     _folder = folder;
     QueryOptions options = new QueryOptions();
     // options.IndexerOption = IndexerOption.DoNotUseIndexer;
     _queryResult = _folder.CreateFileQueryWithOptions(options);
     _queryResult.ContentsChanged += QueryResult_ContentsChanged;
     await UpdateCount();
 }
Example #8
0
        private async Task GetItemsAsync()
        {
            QueryOptions options = new QueryOptions();

            options.FolderDepth = FolderDepth.Deep;
            options.FileTypeFilter.Add(".jpg");
            options.FileTypeFilter.Add(".png");
            options.FileTypeFilter.Add(".gif");

            // Get the Pictures library
            Windows.Storage.StorageFolder picturesFolder = Windows.Storage.KnownFolders.PicturesLibrary;
            var result = picturesFolder.CreateFileQueryWithOptions(options);

            IReadOnlyList <StorageFile> imageFiles = await result.GetFilesAsync();

            bool unsupportedFilesFound = false;

            foreach (StorageFile file in imageFiles)
            {
                // Only files on the local computer are supported.
                // Files on OneDrive or a network location are excluded.
                if (file.Provider.Id == "computer")
                {
                    Images.Add(await LoadImageInfo(file));
                }
                else
                {
                    unsupportedFilesFound = true;
                }
            }

            ImageGridView.ItemsSource = Images;

            if (unsupportedFilesFound == true)
            {
                ContentDialog unsupportedFilesDialog = new ContentDialog
                {
                    Title           = "Unsupported images found",
                    Content         = "This sample app only supports images stored locally on the computer. We found files in your library that are stored in OneDrive or another network location. We didn't load those images.",
                    CloseButtonText = "Ok"
                };

                ContentDialogResult resultNotUsed = await unsupportedFilesDialog.ShowAsync();
            }
        }
Example #9
0
 public WatchedFolder(StorageFolder folder)
 {
     _folder = folder;
     _fileQueryResult = _folder.CreateFileQueryWithOptions(_queryOptions);
     _fileQueryResult.ContentsChanged += _fileQueryResult_ContentsChanged;
 }
Example #10
0
        /// <summary>
        /// Generates html for the gallery
        /// </summary>
        /// <param name="folder">Folder to read the pictures from</param>
        /// <param name="pageNumber">Page starting from 1</param>
        /// <param name="pageSize">Number of pictures on each page</param>
        /// <returns></returns>
        public async Task<string> GenerateGallery(StorageFolder folder, int pageNumber, int pageSize)
        {
            // Don't allow negatives
            if (pageNumber < 1) pageNumber = 1;
            if (pageSize < 1) pageSize = 1;

            var subFolders = await folder.GetFoldersAsync();
            var parentFolder = await folder.GetParentAsync();

            // JavaScript code for toggling the subfolder list
            string html = "";
            html += "<script type='text/javascript'>" +
                "function toggleSubfolderList(){"+
                "var folderNavPane = document.getElementById('folder_nav_pane');" +
                "if(folderNavPane.style.display == 'block') folderNavPane.style.display = 'none';" +
                "else folderNavPane.style.display = 'block'" +
                "}" +
                "</script>";

            html += "<table>";
            html += "<tr><td>";
            // Create breadcrumbs for folder nav
            var temp = folder;
            string breadcrumbs = "<b>"+ ((subFolders.Count > 0) ? "<a onclick='toggleSubfolderList()' href='javascript:void(0);'>" + temp.Name + "</a>" : temp.Name) + "</b>";
            while(!temp.Path.Equals(rootFolder.Path, StringComparison.OrdinalIgnoreCase))
            {
                temp = await temp.GetParentAsync();
                string hyperlink = MakeHyperlink(temp.Name, "/gallery.htm?folder=" + WebUtility.UrlEncode(temp.Path), false);
                breadcrumbs = hyperlink + " > " + breadcrumbs;
            }
            html += breadcrumbs + "<br>";

            if (subFolders.Count > 0)
            {
                // Generate subfolder navigation pane
                html += "<div id='folder_nav_pane' style='display:none'>";
                html += "<ul>";
                foreach (StorageFolder subFolder in subFolders)
                {
                    html += "<li><a href='/gallery.htm?folder=" + WebUtility.UrlEncode(subFolder.Path) + "'>" + subFolder.Name + "</a></li>";
                }
                html += "</ul></div>";
            }

            html += "<br></td></tr>";

            // Get the files in current folder and subfolders
            var queryOptions = new QueryOptions();
            queryOptions.FolderDepth = FolderDepth.Deep;

            var results = folder.CreateFileQueryWithOptions(queryOptions);
            
            StorageFile[] sortedFiles = null;

            // Use cached files if we already got the files and we're navigating to the first page
            if (cachedFiles != null && pageNumber != 1)
            {
                sortedFiles = cachedFiles;
            }
            else
            {
                var files = await results.GetFilesAsync();
                sortedFiles = files.OrderByDescending((x) => x.DateCreated).ToArray();
                cachedFiles = sortedFiles;
            }

            if (sortedFiles.Length > 0)
            {
                // Create pages
                string pagesHtml = "<form>";
                html += "<tr><td>";
                int totalPages = (int)Math.Ceiling((double)sortedFiles.Length / pageSize);
                pagesHtml += "Pages: ";

                pagesHtml += "<select name='page' onchange='this.form.submit()'>";

                for (int i = 1; i <= totalPages; i++)
                {
                    pagesHtml += "<option value='" + i + "' " + ((i == pageNumber) ? "selected='selected'" : "") + ">" + i + "</option>";
                }
                pagesHtml += "</select>";
                pagesHtml += "<input type='hidden' name='folder' value='" + folder.Path + "' />";
                pagesHtml += "<input type='hidden' name='pageSize' value='30' />";
                pagesHtml += "</form>";

                html += pagesHtml;
                html += "<br></td></tr>";

                html += "<tr><td>";

                // Pick out the subset of files we need based on page
                int startIndex = (pageNumber - 1) * pageSize;
                for (int i = startIndex; i < startIndex + pageSize; i++)
                {
                    if (i < sortedFiles.Length)
                    {
                        StorageFile file = sortedFiles[i];
                        html += "<div class='img'>";
                        html += "<a target='_blank' href='/api/gallery/" + WebUtility.UrlEncode(file.Path) + "'>";
                        html += "<img src='/api/gallery/" + WebUtility.UrlEncode(file.Path) + "' alt='" + file.Name + "' width='190'>";
                        html += "<div class='desc'><b>File Name:</b> " + file.Name + "<br><b>Date Created:</b> " + file.DateCreated + "</div>";
                        html += "</a>";
                        html += "</div>";
                    }
                }

                html += "</td></tr>";

                // Create pages
                html += "<tr><td>";
                html += "<br>" + pagesHtml;
                html += "</td></tr>";
            }
            else
            {
                html += "No pictures found in " + folder.Path;
            }

            html += "</table>";

            return html;
        }
        /// <summary>
        /// 
        /// </summary>
        public async void RefreshQueue()
        {
            try
            {
                reportFolder = await KnownFolders.DocumentsLibrary.CreateFolderAsync("311_Reports_Folder", CreationCollisionOption.OpenIfExists);
            }
            catch (Exception) { /*NotifyUser("DOCUMENT ERROR", NotifyType.ReportMessage);*/ }

            try
            {
                pictureFolder = await KnownFolders.PicturesLibrary.CreateFolderAsync("311_Pictures_Folder", CreationCollisionOption.OpenIfExists);
            }
            catch (Exception) { /*NotifyUser("PICTURE ERROR", NotifyType.ReportMessage);*/ }

            var queryOptions = new QueryOptions(CommonFileQuery.DefaultQuery, new[] { ".txt" });
            var query = reportFolder.CreateFileQueryWithOptions(queryOptions);
            var report_files = await query.GetFilesAsync();

            queryOptions = new QueryOptions(CommonFileQuery.DefaultQuery, new[] { ".png" });
            query = pictureFolder.CreateFileQueryWithOptions(queryOptions);
            var picture_files = await query.GetFilesAsync();

            //if (report_files.Count != picture_files.Count)
            //{
            //   await RemoveQueue(true);
            //}

            if ((queuedReportCount = report_files.Count) > 0)
            {
                ShowQueue(report_files, picture_files);
            }
            else
            {
                QueuedListView.Items.Clear();
                queuedListIndex.Clear();
            }
        }
        /// <summary>
        /// Finds and displays the first image file on the storage.
        /// </summary>
        /// <param name="storage"></param>
        async private Task GetFirstImageFromStorageAsync(StorageFolder storage)
        {
            var storageName = storage.Name;

            // Construct the query for image files
            var queryOptions = new QueryOptions(CommonFileQuery.OrderByName, new List<string> { ".jpg", ".png", ".gif" });
            var imageFileQuery = storage.CreateFileQueryWithOptions(queryOptions);

            // Run the query for image files
            rootPage.NotifyUser("[Launched by Autoplay] Looking for images on " + storageName + " ...", NotifyType.StatusMessage);
            var imageFiles = await imageFileQuery.GetFilesAsync();
            if (imageFiles.Count > 0)
            {
                var imageFile = imageFiles[0];
                rootPage.NotifyUser("[Launched by Autoplay] Found " + imageFile.Name + " on " + storageName, NotifyType.StatusMessage);
                await DisplayImageAsync(imageFile);
            }
            else
            {
                rootPage.NotifyUser("[Launched by Autoplay] No images were found on " + storageName + ". You can use scenario 2 to transfer an image to it", NotifyType.StatusMessage);
            }
        }
Example #13
0
        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;
        }
 private StorageFileQueryResult getResourceFilePaths(StorageFolder folder, IEnumerable<string> fileTypeFilters)
 {
     QueryOptions queryOptions = new QueryOptions(CommonFileQuery.OrderByName, fileTypeFilters);
     queryOptions.FolderDepth = FolderDepth.Deep;
     return folder.CreateFileQueryWithOptions(queryOptions);
 }
Example #15
0
        private async Task AddFiles(StorageFolder parentFolder)
        {
            var fileQuery = parentFolder.CreateFileQueryWithOptions(
                new QueryOptions(Windows.Storage.Search.CommonFileQuery.OrderByDate, new string[] { ".jpg", ".png" })
                );

            //Find up to 250 pictures in all sub folders of the parent folder

            var files = await fileQuery.GetFilesAsync(0, 250);

            foreach (var file in files)
            {
                string fileType = file.FileType.ToLowerInvariant();
                switch (fileType)
                {
                    case ".jpg":
                    case ".png":
                        lock (_allUris)
                        {
                            if (_allUris.Count >= MaxPhotos)
                            {
                                return;
                            }

                            string pathname = file.Path;
                            Uri uri = new Uri(pathname, UriKind.Absolute);
                            _allUris.Add(uri);
                        }
                        break;
                }
            }
        }