FeaturedIT topics

How to use File Providers in ASP.Net Core

File Providers in ASP.Net Core provide a layer of abstraction on the file system, allowing us to easily obtain file and directory information, watch for changes, and of course access physical files. This article examines how we can work with file providers in ASP.Net Core.

File Provider abstractions

The file providers implement the IFileProvider interface. There are three implementations of IFileProvider: Physical, Embedded, and Composite. The IFileProvider is the main interface that exposes the necessary methods to retrieve file information (using the IFileInfo interface) and directory information (using the IDirectoryContents interface). To set up change notifications, you can take advantage of the IChangeToken interface.

Below I’ve listed each file provider class and its purpose. Each of these providers implements the IFileProvider interface.

  • PhysicalFileProvider—used to provide access to the physical file system
  • EmbeddedFileProvider—used to access files inside the assemblies
  • CompositeFileProvider—used to provide combined access; i.e., a single interface used to work with files from multiple providers

Use PhysicalFileProvider in ASP.Net Core

Related Articles

Back to top button