Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to close FileStream without causing an error in "Syncfusion.PdfViewer"?

I’m using Syncfusion.PdfViewer in my project. When I click an item in a list, the related pdf file is loaded and shown in the PdfViewer:

private void PdfReport(string address)
{
    //Load the stream from the local system.
    FileStream fs = new FileStream(address, FileMode.Open);
    PdfSource = fs;
}

The problem is that each time I load a pdf file, a new instance of FileStream is created and the memory usage increases. When I try to close FileStream like the following code, the pdf is not shown in the viewer:

private void PdfReport(string address)
{
    //Load the stream from the local system.
    FileStream fs = new FileStream(address, FileMode.Open);
    PdfSource = fs;
    fs.Dispose();
}

How can I solve this problem?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You should check if a PdfSource exists and if so close/ dispose that before creating the new filestream, so just

if (PdfSource is not null)
    PdfSource.Dispose();

PdfSource = new FileStream(address, FileMode.Open);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading