Unable to Read file from Folder - PnpCore

34 Views Asked by At

I am facing a weird issue while reading files from Sub folder in Documents folder using Pnp.Core. Below is the Code that I have tried till now.

           using(var pnpContext = await pnpContextFactory.CreateAsync("Default")) {
            var documentFolder = (await pnpContext.Web.Lists.GetByTitleAsync("Dokumenter", p => p.RootFolder));
            var allStoreFolders = (await  documentFolder.RootFolder.GetAsync(f => f.Folders)).Folders;
        
            foreach(var folder in allStoreFolders.AsRequested()) {

                //  Console.WriteLine(folder.Name);
                if (folder.Name == "BC10014")
                {
                    Console.WriteLine("Folder Found");
                    await folder.LoadAsync(f => f.Files);

                    foreach (var file in folder.Files.AsRequested())
                    {
                        var extension = Path.GetExtension(file.Name);
                        if (extension == ".txt")
                        {
                            Console.WriteLine($"Filename: {file.ServerRelativeUrl}");

                        }
                    }
                }
            } 

But it never returns the file from the sub folder. My site structure and folders are attached in the screenshot. The only issue i think is the link for Dokumenter has empty space between, i.e Delte%20dokumenter, but I don't know whether this can be the reason.

image

enter image description here

0

There are 0 best solutions below