How to browse a folder in blazor server c#

Anonymous
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

Developer technologies | ASP.NET | ASP.NET Core
Developer technologies | .NET | Blazor
Developer technologies | C#
Developer technologies | 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.
0 comments 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

    0 comments No comments

  2. Bruce (SqlWork.com) 81,606 Reputation points Volunteer Moderator
    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.

    0 comments No comments

  3. Anonymous
    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.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.