Overview

PhysicalFileProvider

IFileProvider provider = new PhysicalFileProvider(applicationRoot);
IDirectoryContents contents = provider.GetDirectoryContents(""); // the applicationRoot contents
IFileInfo fileInfo = provider.GetFileInfo("wwwroot/js/site.js"); // a file under applicationRoot
public class HomeController : Controller
{
    private readonly IFileProvider _fileProvider;

    public HomeController(IFileProvider fileProvider)
    {
        _fileProvider = fileProvider;
    }

    public IActionResult Index()
    {
        var contents = _fileProvider.GetDirectoryContents("");
        return View(contents);
    }
public class Startup
{
	private IHostingEnvironment _hostingEnvironment;
	public Startup(IHostingEnvironment env)
	{
		var builder = new ConfigurationBuilder()
			.SetBasePath(env.ContentRootPath)
			.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
			.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
			.AddEnvironmentVariables();
		Configuration = builder.Build();

		_hostingEnvironment = env;
	}

	public IConfigurationRoot Configuration { get; }

	// This method gets called by the runtime. Use this method to add services to the container.
	public void ConfigureServices(IServiceCollection services)
	{
		// Add framework services.
		services.AddMvc();

		var physicalProvider = _hostingEnvironment.ContentRootFileProvider;
		var embeddedProvider = new EmbeddedFileProvider(Assembly.GetEntryAssembly());
		var compositeProvider = new CompositeFileProvider(physicalProvider, embeddedProvider);

		// choose one provider to use for the app and register it
		//services.AddSingleton<IFileProvider>(physicalProvider);
		//services.AddSingleton<IFileProvider>(embeddedProvider);
		services.AddSingleton<IFileProvider>(compositeProvider);
	}
}

EmbeddedFileProvider