locked
read only specific files from folder

    Question

  • I have two questions:

    1. I want to read only specific type of files from folder like read all text files  ”*.txt” and copy it to another folder after reading. Currently in my folder is where files is saved : Windows.Storage.ApplicationData.Current.LocalFolder

    2. I am using messagebox in my index.html page and 2nd page xyz.html :

    var msgBox=new Windows.UI.Popups.MessageDialog(“Succeess”);
    msgBox.showAsync();

    But in my 2nd page I am getting Access Denied error, but if i am only using it in 2nd page then it is working fine. please tell me why I am getting this error on 2nd page! how can I solve this ? how can I use multiple times message box in all over project ?
    Saturday, April 5, 2014 2:23 PM

Answers

  • I'd expect to see an exception raised, not null.

    Make sure you call AreQueryOptionsSupported to make sure the specific options you list are valid for the folder. Your code looks correct if you use the DefaultQuery or OrderByName, but not for OrderByDate.

    See the CommonFileQuery documentation which says of OrderByDate

    You can use this option only for folders in a library or the HomeGroup folder.

    • Marked as answer by gudd.u Friday, April 11, 2014 7:25 AM
    Thursday, April 10, 2014 1:52 AM
    Owner

All replies

  • Please post separate questions in separate threads.

    For the first: you can use a file query to find just the .txt files.

    For the second: you cannot show a second MessageDialog while a first is already up. You need to wait until it is closed before showing the second. Showing so many dialogues will be annoying to your users. You should redesign to show your errors inline. For debugging, use System.Diagnostics.Debug.

     

    Saturday, April 5, 2014 2:48 PM
    Owner
  • please check this code i am not getting file , what i am missing?
     public static async Task<string> ReadZFolder()
            {
                var folder= Windows.Storage.ApplicationData.Current.LocalFolder;
                var fileInfo = new QueryOptions(CommonFileQuery.OrderByDate, new[] { ".txt" });
    
                var files = await folder.CreateFileQueryWithOptions(fileInfo).GetFilesAsync(0, 20);
                foreach (var file in files)
                {
                   //await ReadZFile(file);
                   getMessage += file.Name.ToString() + "**";
                }
               
                return getMessage ;
            }


    • Edited by gudd.u Monday, April 7, 2014 9:25 AM
    Monday, April 7, 2014 8:26 AM
  • i also tried this, but still getting null
      var queryOptions = new Windows.Storage.Search.QueryOptions(CommonFileQuery.OrderByDate, new[] { ".txt" });
    
                StorageFileQueryResult queryResults = Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileQueryWithOptions(queryOptions);
                IReadOnlyList<StorageFile> files = await queryResults.GetFilesAsync();
    
    
                foreach (var file in files)
                {
                    getMessage += file.Name.ToString();
                }
                return getMessage;

    Monday, April 7, 2014 2:09 PM
  • please check
    Tuesday, April 8, 2014 3:20 AM
  • Do you have any txt files in your local app data directory?

    --Rob

    Tuesday, April 8, 2014 6:07 AM
    Owner
  • yes i have, is my code correct???

    • Edited by gudd.u Tuesday, April 8, 2014 10:47 AM
    Tuesday, April 8, 2014 10:46 AM
  • for the time being I just passed hard code file names using an array but getting an error so I start a new thread and please help me solve these issues:

      http://social.msdn.microsoft.com/Forums/windowsapps/en-US/8150e79a-1012-4e69-8fa6-b3aac380119a/run-sqlquery-from-files-sqlite?forum=winappswithcsharp
    Wednesday, April 9, 2014 8:59 AM
  • I'd expect to see an exception raised, not null.

    Make sure you call AreQueryOptionsSupported to make sure the specific options you list are valid for the folder. Your code looks correct if you use the DefaultQuery or OrderByName, but not for OrderByDate.

    See the CommonFileQuery documentation which says of OrderByDate

    You can use this option only for folders in a library or the HomeGroup folder.

    • Marked as answer by gudd.u Friday, April 11, 2014 7:25 AM
    Thursday, April 10, 2014 1:52 AM
    Owner
  • thanks OrderByName and DefaultQuery  are working.


    • Edited by gudd.u Wednesday, April 16, 2014 11:28 AM
    Friday, April 11, 2014 7:28 AM