locked
Enumerating Files in a Folder

    Question

  • Hello

    I am trying to run the Files Enumeration Example located at

    Folder enumeration sample at MSDN Code Samples (Cannot Include Link Here)

    It has simple button click event which enumerates files in Pictures Library.

    The Problem is that it is not working and giving a COM Exception.

    I am running this on a Windows 8.1 Single Language Edition running on 64 Bit.

    Is my OS the culprit or that code needs modification ?

    System.Runtime.InteropServices.COMException was unhandled by user code
      HResult=-2147467259
      Message=Error HRESULT E_FAIL has been returned from a call to a COM component.
      Source=mscorlib
      ErrorCode=-2147467259
      InnerException:

    public

    Scenario1()

            {

               

    this.InitializeComponent();

                GetFilesAndFoldersButton.Click +=

    newRoutedEventHandler(GetFilesAndFolders_Click);

            }

           

    privateasyncvoidGetFilesAndFolders_Click(objectsender, RoutedEventArgse)

            {

               

    StorageFolderpicturesFolder = KnownFolders.PicturesLibrary;

               

    IReadOnlyList<StorageFile> fileList = awaitpicturesFolder.GetFilesAsync();

               

    IReadOnlyList<StorageFolder> folderList = awaitpicturesFolder.GetFoldersAsync();

    Regards


    Tuesday, May 06, 2014 7:49 AM

Answers

  • Hi,

    I test your code and sample in my computer. I found everything is Ok. I think there is no problem in your code. May be the error occurs due to your computer's environment. You can use another computer to test it or you can reinstall your VS and OS environment.

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, May 07, 2014 6:07 AM

All replies

  • can you share the whole code you have?

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Tuesday, May 06, 2014 9:08 AM
  • http://code.msdn.microsoft.com/windowsapps/Folder-enumeration-sample-33ebd000

    is the code example

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Windows.Storage;
    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Controls;
    using Windows.UI.Xaml.Navigation;

    namespace FolderEnumeration
    {
        public sealed partial class Scenario1 : SDKTemplate.Common.LayoutAwarePage
        {
            public Scenario1()
            {
                this.InitializeComponent();
                GetFilesAndFoldersButton.Click += new RoutedEventHandler(GetFilesAndFolders_Click);
            }

            private async void GetFilesAndFolders_Click(object sender, RoutedEventArgs e)
            {
                StorageFolder picturesFolder = KnownFolders.PicturesLibrary;

                IReadOnlyList<StorageFile> fileList = await picturesFolder.GetFilesAsync();
                IReadOnlyList<StorageFolder> folderList = await picturesFolder.GetFoldersAsync();

                var count = fileList.Count + folderList.Count;
                StringBuilder outputText = new StringBuilder(picturesFolder.Name + " (" + count + ")\n\n");

                foreach (StorageFolder folder in folderList)
                {
                    outputText.AppendLine("    " + folder.DisplayName + "\\");
                }

                foreach (StorageFile file in fileList)
                {
                    outputText.AppendLine("    " + file.Name);
                }

                OutputTextBlock.Text = outputText.ToString();
            }
        }
    }

    Tuesday, May 06, 2014 10:04 AM
  • Hi,

    I test your code and sample in my computer. I found everything is Ok. I think there is no problem in your code. May be the error occurs due to your computer's environment. You can use another computer to test it or you can reinstall your VS and OS environment.

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, May 07, 2014 6:07 AM
  • yeah thanks a lot for your time, it's probabaly due to Visual Studio

    Will check and will post my findings here.

    Thanks once again.

    Wednesday, May 07, 2014 7:11 AM