locked
How come QueryOptions of ".xps, .pdf" fetch also ".oxps" files? RRS feed

  • Question

  • var SUPPORTED_FILE_EXTENSIONS = [
        ".jpg", ".jpeg", 
        ".png", 
        ".bmp", 
        ".tiff", ".tif", 
        ".pdf", 
        ".xps", 
        ".docx", ".doc", ".dot", ".docx", ".docm", 
        ".xlsx", ".xlsm",
        ".odt", ".ods", ".odg", ".odp",
        ".txt", ".md", ".markdown", ".textile"
      ]


    queryOptions = new Windows.Storage.Search.QueryOptions(Windows.Storage.Search.CommonFileQuery.orderByName, SUPPORTED_FILE_EXTENSIONS)
    fileQuery = folder.createFileQueryWithOptions(queryOptions)

    This will also select files with the "oxps" extension. How come? I want ONLY the files in the supported file extensions array to be returned from the query.

          
    Monday, December 17, 2012 11:18 AM

Answers

  • Hi,

    I have reproduce your scenario on my side. And don't has this problem. I just get the file with ".xps", and don't get the ".oxps". Please test again. The code I using as follow:

    (function () {
        "use strict";
    
        var page = WinJS.UI.Pages.define("/html/scenario1.html", {
            ready: function (element, options) {
                document.getElementById("search").addEventListener("click", search, false);
            }
        });
    
        function search() {
            // Initiate the div elements
            var outputDiv = document.getElementById("output");
            var queryBox = document.getElementById("queryBox");
    
            // Retrieve the query entered in the textbox
            var searchFilter = queryBox.value;
    
            // Create a new file query from the music library and apply the AQS filter
            var SUPPORTED_FILE_EXTENSIONS = [
         ".jpg", ".jpeg",
         ".png",
         ".bmp",
         ".tiff", ".tif",
         ".pdf",
         ".xps",
         ".docx", ".doc", ".dot", ".docx", ".docm",
         ".xlsx", ".xlsm",
         ".odt", ".ods", ".odg", ".odp",
         ".txt", ".md", ".markdown", ".textile"
            ];
            var musicLibrary = Windows.Storage.KnownFolders.musicLibrary;
            var pictureLibrary = Windows.Storage.KnownFolders.picturesLibrary;
            var options = new Windows.Storage.Search.QueryOptions(Windows.Storage.Search.CommonFileQuery.orderBySearchRank, SUPPORTED_FILE_EXTENSIONS);
           // options.userSearchFilter = searchFilter;
            var fileQuery = pictureLibrary.createFileQueryWithOptions(options);
            fileQuery.getFilesAsync().done(function (files) {
                if (files.size === 0) {
                    outputDiv.innerHTML = "No files found for \"<b>" + searchFilter + "</b>\"";
                } else {
                    // Create an output string to hold results count and filenames
                    var filesLabel = (files.size === 1) ? "file" : "files";
                    var output = "<b>" + files.size + " " + filesLabel + " found</b><br>";
    
                    // Iterate through the results and print each filename to the output field
                    files.forEach(function (file) {
                        output += file.name + "<br>";
                    });
                    outputDiv.innerHTML = output;
                }
            });
        }
    })();

    You could download the sample at: http://code.msdn.microsoft.com/windowsapps/Programmatically-searching-25e1a56b . And then just change the code

    scenario1.js

    as above.


    Roy
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Song Tian Friday, December 21, 2012 9:59 AM
    Tuesday, December 18, 2012 7:18 AM

All replies

  • Hi,

    I have reproduce your scenario on my side. And don't has this problem. I just get the file with ".xps", and don't get the ".oxps". Please test again. The code I using as follow:

    (function () {
        "use strict";
    
        var page = WinJS.UI.Pages.define("/html/scenario1.html", {
            ready: function (element, options) {
                document.getElementById("search").addEventListener("click", search, false);
            }
        });
    
        function search() {
            // Initiate the div elements
            var outputDiv = document.getElementById("output");
            var queryBox = document.getElementById("queryBox");
    
            // Retrieve the query entered in the textbox
            var searchFilter = queryBox.value;
    
            // Create a new file query from the music library and apply the AQS filter
            var SUPPORTED_FILE_EXTENSIONS = [
         ".jpg", ".jpeg",
         ".png",
         ".bmp",
         ".tiff", ".tif",
         ".pdf",
         ".xps",
         ".docx", ".doc", ".dot", ".docx", ".docm",
         ".xlsx", ".xlsm",
         ".odt", ".ods", ".odg", ".odp",
         ".txt", ".md", ".markdown", ".textile"
            ];
            var musicLibrary = Windows.Storage.KnownFolders.musicLibrary;
            var pictureLibrary = Windows.Storage.KnownFolders.picturesLibrary;
            var options = new Windows.Storage.Search.QueryOptions(Windows.Storage.Search.CommonFileQuery.orderBySearchRank, SUPPORTED_FILE_EXTENSIONS);
           // options.userSearchFilter = searchFilter;
            var fileQuery = pictureLibrary.createFileQueryWithOptions(options);
            fileQuery.getFilesAsync().done(function (files) {
                if (files.size === 0) {
                    outputDiv.innerHTML = "No files found for \"<b>" + searchFilter + "</b>\"";
                } else {
                    // Create an output string to hold results count and filenames
                    var filesLabel = (files.size === 1) ? "file" : "files";
                    var output = "<b>" + files.size + " " + filesLabel + " found</b><br>";
    
                    // Iterate through the results and print each filename to the output field
                    files.forEach(function (file) {
                        output += file.name + "<br>";
                    });
                    outputDiv.innerHTML = output;
                }
            });
        }
    })();

    You could download the sample at: http://code.msdn.microsoft.com/windowsapps/Programmatically-searching-25e1a56b . And then just change the code

    scenario1.js

    as above.


    Roy
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Song Tian Friday, December 21, 2012 9:59 AM
    Tuesday, December 18, 2012 7:18 AM
  • The file in question that is selected has 2 "extensions" like this ".pdf.oxps" It should not be selected, shouldn't it?
    Friday, December 21, 2012 10:54 AM