Is there a way to pull info from a file in the solution explorer and display it on a blazer server app? (not sure if this is allowed)

146 Views Asked by At

I currently am developing a document app with blazor server. I have managed to get it to pull the pdf which is stored in a folder in the solution explorer and got it to download onto the users pc - but I was wondering if theres any way of pulling info from the file like date created, filename or even a preview picture? I've attached the code below that allows them to download the pdf if that helps.

//this code is in my @code section of my .razor file

async Task DownloadBinary()
    {
        foreach() {

        }
    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 presses it it starts downloading the file - it is also in my .razor file

<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>

I have tried googling it but don't see anything about how to do what im looking for, like I said if this question isnt allowed please let me know and ill ask elsewhere. Any links to articles or youtube videos would be helpful - thanks in advance.

1

There are 1 best solutions below

0
Megan Paterson On

I ended up scraping Blazor all together and used ASP.NET Core web application instead.