none
Load RDLC and Subreport RDLC's From Different NameSpace / Assembly RRS feed

  • Question


  • Hi everyone,

    In an effort to keep thing complicated I have a separate dll/namespace containing a MasterRDLC and subreportRDLC's.
    My test application contains a reportviewer that needs access to those files.  I searched around the forums but did not find an answer that I was able to follow.


    Form NameSpace: TestFormApplication
    RDLC DLL Namespace: ReportLibrary
    A reference to ReportLibrary.dll  and the ReportLibrary namespace has been added to my TestFormApplication project


    The following code fails - the reportviewer is unable to locate the RDLC File:
    Me.ReportViewer1.LocalReport.ReportEmbeddedResource = "ReportLibrary.MasterSubReportContainer.rdlc" 


    I then tried to give the reportViewer control access to the dll
    1Me.ReportViewer1.LocalReport.ExecuteReportInCurrentAppDomain(AppDomain.CurrentDomain.Evidence) 
    2Me.ReportViewer1.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("ReportLibrary, Version=1.0.0.0, _
                    Culture=neutral, PublicKeyToken=null"




    This still fails.

    I've been searching the Forums and found one post that looked very useful:
    Here

    The solution (that I do not follow) was:
    [quote]
    There are no limitations on the namespace of the embedded resource.

    If your resource is in a separate assembly from the code that sets the property, the control has no way of knowing that and will try to load the resource from the wrong assembly.  In this case, you could load the resource manually and call LoadReportDefinition with the manifest stream.
    [/end quote]

    But I do not understand how that would work. 
    1) How would I load a stream from a dll (the ResourceReader asks for a file but I won't know where the dll is at runtime)?
    2) And how would that work given that there are also an unknown group of subreport.rdlc files that I would need to pull from the assembly.

    Ideally I would like to just give reportviewer access to the assembly and its embedded resources.

    Any help would be greatly appreciated.

    - Jordan

    PS: using VS2008 / Report Viewer 2008
    • Edited by Jordan At Kawa Wednesday, July 30, 2008 2:48 AM Marked code segments as code
    Wednesday, July 30, 2008 2:42 AM

Answers

  • maybe you should revamp the entire .rdlc loading system?

    I'm not sure how your getting your datasources, but would it be possible to store report and subreport info there? 


    I use one webpage to show 75 different reports at this time, and it's designed to handle an unlimited amount.  All data is stored in a file server, and basically I  just store the .rdlc info with the data.  That way  my report page always has the right rdlc based on the data being provided.

    In regards to the .rdlc themselves.  I don't include them in the project.  They made the size of the .dll file enormous.  So they just have their own folder on the webserver, and I just load them with  a  Server.Mappath method.

    this eliminates any issues with .dll, and also elimnates any worry about getting the right .rdlc.




    Living my life at 123mph in 11.15 seconds
    Wednesday, July 30, 2008 1:41 PM
  • Hey Blast,

    I'm actually considering storing "report metadata" in the dll that would provide the list of subreports . . . or maybe try a better method of retrieving them in the dll

    (Like maybe create class in the report dll that receives a reference to the reportViewer control and loads the local report).

    That way the view doesn't have to understand the concept of rdlc stream loading.


    Still I feel like there must be a better way.

    If there are any suggestions I'm all ears . . . .
    Wednesday, July 30, 2008 10:48 PM

All replies



  • OK so I figured out how to load the MasterSubreportContainer.rdlc

      - I had better luck using MSDN search to find what I needed in the forums. Partial Solution

    So here is my new code - So far so Good . . .

    1    Private Sub LoadRDLCFromStream() 
    2        Dim asm As Assembly = Assembly.Load("ReportLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
    3        Dim ioStream As IO.Stream = asm.GetManifestResourceStream("ReportLibrary.MasterSubReportContainer.rdlc"
    4        Me.ReportViewer1.LocalReport.LoadReportDefinition(ioStream) 
    5    End Sub 


    But now I can't figure out how to load the subreports.
    The problem is that I won't know the subreport names in advance.

    I tried to call the following code block in the SubReportProcessingEventHandler  but the handler apparently never gets called until the subreport rdlc is defined.  So its a catch 22 - need the name of the subreport to load it, can't get the name from the handler until the rdlc is loaded.

    Ideally I would like to call something like this . . . but again, I don't know what the names are ahead of time.
        Private Sub LoadSubReportStream(ByVal name As String
            name = "ReportLibrary." & name & ".rdlc" 
            Dim ioStream As IO.Stream = asm.GetManifestResourceStream("ReportLibrary.MasterSubReportContainer.rdlc"
            Me.ReportViewer1.LocalReport.LoadSubreportDefinition(name, ioStream) 
        End Sub 

    Wow, its nearly midnight.  Heading home, if anyone on the other side of the world (or this side for that matter) sees this I would greatly appreciate the help.

    Thanks,

    Jordan
    Wednesday, July 30, 2008 3:41 AM
  • maybe you should revamp the entire .rdlc loading system?

    I'm not sure how your getting your datasources, but would it be possible to store report and subreport info there? 


    I use one webpage to show 75 different reports at this time, and it's designed to handle an unlimited amount.  All data is stored in a file server, and basically I  just store the .rdlc info with the data.  That way  my report page always has the right rdlc based on the data being provided.

    In regards to the .rdlc themselves.  I don't include them in the project.  They made the size of the .dll file enormous.  So they just have their own folder on the webserver, and I just load them with  a  Server.Mappath method.

    this eliminates any issues with .dll, and also elimnates any worry about getting the right .rdlc.




    Living my life at 123mph in 11.15 seconds
    Wednesday, July 30, 2008 1:41 PM
  • Hey Blast,

    I'm actually considering storing "report metadata" in the dll that would provide the list of subreports . . . or maybe try a better method of retrieving them in the dll

    (Like maybe create class in the report dll that receives a reference to the reportViewer control and loads the local report).

    That way the view doesn't have to understand the concept of rdlc stream loading.


    Still I feel like there must be a better way.

    If there are any suggestions I'm all ears . . . .
    Wednesday, July 30, 2008 10:48 PM
  • I actually figured out how to call the subreport but then also parameters for the drill down are not returned to the subreport calling section.

    protected void rv_Drillthrough(object sender, DrillthroughEventArgs e)
      {
        
        ////user via e.Report.GetParameters()
        Assembly asm = Assembly.Load("Reports, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
        System.IO.Stream iostream = asm.GetManifestResourceStream("Reports." + e.ReportPath + ".rdlc");
        this.rv.LocalReport.LoadReportDefinition(iostream);    
      }
    
    This is a drillthrough event handler for the reportviewer control. We can actually get the subreport to be called but we cannot get the values passed to this subreport from the parent report.

    Actually i have a parentreport.rdlc and a subreport.rdlc in another assembly. When i try to drill down from the parent to the child report it sends me to this reportviewer_Drillthrough event where i can again call the subreport but i do not have any idea of the passed parameters from the parent section.

    Any help regarding drilldown report in another assembly is highly appreciated.

    prem
    Thursday, April 21, 2011 8:16 AM