Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

embeddedProvider.GetDirectoryContents returns 0 results

There are many posts on SO about how to access resource files. I'm very lost as to if one is preferred, or whether they are just different options.

.NET Core 3.1, Class Library

I created a new folder in my project, called ResourceFiles and added many files

I opened the csproj and added

<EmbeddedResource Include="ResourceFiles/*" />

And to consume this, I have

using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.FileProviders.Embedded;

namespace Core.Html  
{
    internal static class Template
    {
        internal static string Get()
        {
            var embeddedProvider = new EmbeddedFileProvider(Assembly.GetExecutingAssembly());
            using (var reader = embeddedProvider.GetFileInfo("file.txt").CreateReadStream())
            {
                //stuff
            }
        }
     }
}

This works great for a single file.

What I'd like to be able to do is return a collection of FileInfo because in the ResourceFiles directory, there are many files.

I was hoping to do the following

var allFiles = embeddedProvider.GetDirectoryContents("ResourceFiles");

This always returns an empty list. I don't understand why. What am I doing wrong?

like image 707
MyDaftQuestions Avatar asked Sep 17 '25 23:09

MyDaftQuestions


1 Answers

Looking at the source of EmbeddedFileProvider it only supports files in the root. If you supply anything other than "/" this method will fail.

like image 158
Nate Avatar answered Sep 19 '25 13:09

Nate