1. 文件提供程序核心类型
- IFileProvider
- IFileInfo
- IDirectoryContents
2. 内置文件提供程序
- PhysicalFileProvider (物理文件的提供程序)
- EmbeddedFileProvider (嵌入式的文件提供程序)
- CompositeFileProvider (组合文件提供程序)
3. PhysicalFileProvider 代码
IFileProvider prov = new PhysicalFileProvider(AppDomain.CurrentDomain.BaseDirectory);
var contents = prov.GetDirectoryContents("/");
foreach (var item in contents)
{
//var stream = item.CreateReadStream(); //得到文件流
Console.WriteLine(item.Name);
}
4. EmbeddedFileProvider 代码(测试无效)
IFileProvider prov2 = new EmbeddedFileProvider(typeof(Program).Assembly);
var json = prov2.GetFileInfo("emb.json");
5. CompositeFileProvider 代码
IFileProvider prov = new PhysicalFileProvider(AppDomain.CurrentDomain.BaseDirectory);
IFileProvider prov2 = new EmbeddedFileProvider(typeof(Program).Assembly);
var json = prov2.GetFileInfo("emb.html");
IFileProvider provAll = new CompositeFileProvider(prov, prov2);
var contentAll = provAll.GetDirectoryContents("/");
foreach (var item in contentAll)
{
Console.WriteLine(item.Name);
}