I tried different versions of StaticFiles.But it shows error because IApplicationBuilder does not contain UseStaticFiles().
"Microsoft.AspNetCore.StaticFiles": "1.1.1"
I am using the exact code provided in the .net documentation by Microsoft. Here is what I have in Startup.cs. Note: app is an IApplicationBuilder
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(
PathString.Combine(Directory.GetCurrentDiriectory(), @"Files")),
RequestPath = new PathString("/Files")
});
To put it in context, I want to read the directories and files inside the "Files" folder. Here is the line of code I am using to read the content of the folder but it always returns null. Note: "initialFilePath" is relative path to the folder "File".
var contents = _fileProvider.GetDirectoryContents(initalFilePath);
Thanks
Add nuget package "Microsoft.AspNetCore.StaticFiles"
Open your csproj files in notepad and make sure you have the following line.
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.2" />
If not, add it and reload the project and rebuild.
You are almost certainly missing a using
statement. The extension method UseStaticFiles
is in the Microsoft.AspNetCore.Builder
namespace. just add this to the top of your Startup.cs
:
using Microsoft.AspNetCore.Builder;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With