How set Pdfviewer "downloadfilename" dinamically in a blazor component

Is there a way to set the download file name dynamically on the pdf viewer component?

When i call the Load () function the "downloadfilename" in the component turns null. I tried many ways and the result its the same.

How can i force the "downloadfilename" to be setted?




Index:

<button @onclick="ShowAndLoadPdfViewer" style="margin:100px">SHOW PDF VIEWER</button>
<PdfVisorComponent @ref="PDFViewer"></PdfVisorComponent>
@code
{
    PdfVisorComponent PDFViewer = new PdfVisorComponent();
    public async Task ShowAndLoadPdfViewer()
    {
        await PDFViewer.LoadPdfViewerAsync();
    }
}

Blazor Component (PdfVisorComponent):
SfDialog ID="PdfModal"    @ref="PdfModal"   AllowDragging="true"
          Visible="false" Target="Grid"  Height="770px"   Width="1140px"
          ShowCloseIcon="true" CssClass="e-dlg-header-viewer">
    <DialogTemplates>
        <Header></Header>
        <Content>
            <SfPdfViewerServer @ref="@PDFViewer"
                               DocumentPath="@DocumentPath"
                               DownloadFileName="@DownloadName"
                               Height="500px"
                               Width="1060px">
            </SfPdfViewerServer>
        </Content>
    </DialogTemplates>
</SfDialog>
@code
{
    private SfDialog PdfModal = new SfDialog();
    private SfPdfViewerServer PDFViewer = new SfPdfViewerServer();
    public string DocumentPath { get; set; }
    public string DownloadName { get; set; }
    public async Task LoadPdfViewerAsync()
    {
        DocumentPath = "wwwroot/data/test.pdf";
        DownloadName = "NameTestdinamic.pdf";
        await PDFViewer.LoadAsync("wwwroot/data/test.pdf", null);
        await PdfModal.ShowAsync();
    }
}



Attachment: TestApp_d7d9bf16.rar


5 Replies 1 reply marked as answer

VS Vasugi Sivajothi Syncfusion Team December 3, 2021 12:42 PM UTC

Hi Nelson, 
 
Thank you for contacting Syncfusion support. 
 
We have already resolved the issue “DownloadFileName doesn't work” in the version v19.2.0.57. Kindly upgrade to that version or to the latest version v19.3.0.55 to resolve the issue. And if you want to set the DownloadFileName after rendering the component we suggest you use the below code snippet to set the file name. 
 
Code Snippet: 
 
  public async Task LoadPdfViewerAsync() 
    { 
        PDFViewer.DownloadFileName = "NameTestdinamic.pdf"; 
        await PDFViewer.LoadAsync("wwwroot/data/test.pdf", null); 
        await PdfModal.ShowAsync(); 
    } 
 
 
Kindly try this and let us know if you have any concerns about this. 
 
Regards, 
Vasugi. 



NE Nelson December 3, 2021 08:19 PM UTC

Hi, thanks for the reply.
I upgraded to the version 19.2.0.57 and tried the code but still not loading the downloadfile name (I tried in the sample  atached) . Can you please atach a sample working?

Thanks again


Attachment: TestApp_36795c24.rar


VS Vasugi Sivajothi Syncfusion Team December 6, 2021 08:34 AM UTC

Hi Nelson, 

We suggest you use the StateHasChanged() method after setting the download name property to re-render the component again. We have shared the modified sample for your reference which can be downloaded from the below link. 


Kindly try this and let us know if you have any concerns about this. 

Regards, 
Vasugi. 


Marked as answer

NE Nelson December 6, 2021 12:00 PM UTC

Thanks for the reply.

All working fine now :D

Regards


VS Vasugi Sivajothi Syncfusion Team December 7, 2021 10:14 AM UTC

Hi Nelson, 
 
Thank you for the update. We are glad to know that the issue was resolved. Please revert to us if you need any further assistance. 
 
Regards, 
Vasugi. 
 


Loader.
Up arrow icon