majorsilence / My-FyiReporting

Majorsilence Reporting, .NET report designer and viewer. Fork of fyireporting,
Apache License 2.0
348 stars 201 forks source link

SourceFile and SourceRdl mutually exclusivity during PrintClicked() #157

Open Daaell opened 7 years ago

Daaell commented 7 years ago

I try to embed the .rdl file into the compiled .exe.

First i tried to use the SourceFile property, but i gave up on it, because i couldn't get a Uri for the resource file. Instead i used SourceRdl, which worked:

viewer.SourceRdl = System.Text.Encoding.UTF8.GetString(Properties.Resources.report_file)

This works, the report shows up correctly in the viewer, i'm able to use the ViewerToolstrip's Save, to save out a pdf, etc.

But when i tried to Print() it, i got a NullReferenceException because i'm using SourceRdl. And if SourceRdl is set, SourceFile is null, but Print() tries to access 'SourceFile.LocalPath'

    private void PrintClicked(object sender, System.EventArgs e)
    {
        if (Viewer == null)
        {
            return;
        }

        PrintDocument pd = new PrintDocument();
        pd.DocumentName = Viewer.SourceFile.LocalPath; <- NullReferenceException
        pd.PrinterSettings.FromPage = 1;
        pd.PrinterSettings.ToPage = Viewer.PageCount;
        pd.PrinterSettings.MaximumPage = Viewer.PageCount;