How to pull file name from solution explorer? - In blazor server app/c sharp

Megan Paterson 1 Reputation point
2022-09-12T08:41:07.207+00:00

I am creating an application which allows users to download pdf's which will be stored within the solution explorer - this works fine but is there any way of me pulling info from the file? - file name, folder name etc.

The code im using to download the file is as below if this helps.

the below code is in the @Aidan Wick section of my .razor file

async Task DownloadBinary()
{

FileStream fs = new FileStream("C://Development//CsharpApplications//AlbertBartletPortal//AlbertBartletPortal//PDFs//P45.pdf", FileMode.Open, FileAccess.Read);  
    byte[] pdfData = new byte[fs.Length];  
    fs.Read(pdfData, 0, Convert.ToInt32(fs.Length));  
    fs.Close();  
    // Send the data to JS to actually download the file  
    try  
    {  
        await JSRuntime.InvokeVoidAsync("BlazorDownloadFile", "P45.pdf", "application/octet-stream", pdfData);  
    }  
    catch(Exception ex)  
    {  
          
    }  

}  

this code displays a white card with a download image and if the user clicks it downloads the file and the following code is within the .razor file as well

`

<h1 class="text-center text-white pt-5">Purchase Order's</h1>  
    <div class="card-deck">  
    <div class="card" @onclick="DownloadBinary" style="color:white; width: 200px; height: 150px">  
        @*<img class="img-thumbnail" src="@item.ImageURL">*@  
        <div class="card-body">  
            <h5 class="card-title mb-3">  
                @*@item.Name*@  
                <p style="color: black"> Megan Paterson - p45</p>  
            </h5>  
            <p class="card-text">  
                @*<b>@item.Price.ToString("C")</b>*@  
            </p>  
            <center><img src="Images/img.png" width="40px" height="40px" /></center>  
        </div>  
    </div>  

Once this is working, I will be pulling the foldername and using this to filter out the data.

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,390 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,254 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.
10,247 questions
{count} votes