How to browse a folder in blazor server c#

Lou, Kecheng 0 Reputation points
2023-01-22T16:34:13.5833333+00:00

The blazor server app has a folder that contains pdf files, the folder has web config file, see the below

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <directoryBrowse enabled="true" showFlags="Date, Time, Size, Extension, LongDate" />
    </system.webServer>
</configuration>

I use the following <a> html link to browse the folder, it work on asp.net form project, but does not work on blazor server project, get "Sorry, there's nothing at this address." message. this folder is in wwwroot folder.

<a href="./PDFFiles/Production">View Production Files</a>

how to resolve this issue? thanks

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
2,585 questions
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
795 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
6,999 questions
No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Anderson Kovalski 21 Reputation points
    2023-01-22T17:36:02.8833333+00:00

    You need to enable static assets

    [https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/static-files?view=aspnetcore-7.0

    No comments

  2. Bruce (SqlWork.com) 28,276 Reputation points
    2023-01-22T19:27:48.1866667+00:00

    because there is no file extension, the javascript routing for blazor will try to route to a blazor page.

    you should make the pdf folder a peer, and define a folder for the blazor app

    .if you define the static file handler, you coudl use <a target="_blank ...> to bypass the javascript router.

    No comments

  3. Lou, Kecheng 0 Reputation points
    2023-01-23T15:13:34.1633333+00:00

    I did resolve it.

    use the following, instead of <a href=".\PDFFiles\Production">Production</a>

    <a href=".\wwwroot\PDFFiles\Production">Production</a>

    the PDFFile Folder is inside wwwroot folder.

    Thank you.

    No comments