Programmatically run SSRS report/export in C# UI Model

Hi. Is there a way to run an SSRS report through the C# code in a UI Model project? I was tinkering around and it looks like Microsoft has classes for running reports (Microsoft.Reporting.WebForms) but there are parameters/credentials required to utilize methods from those classes. Is there a way to pull these credentials (username/password/server name/etc.) from within a UI Model?

Comments

  • @Hung Tran

    Yes, you are able to access the SSRS reports using the AppFxWebService. There is a method called ReportsExport that you can use, you just need to supply the Spec ID for the report, a DataFormItem with the parameters, and the export type. This is a snippet where I have used this:

    Dim svc = New AppFxWebService(GetRequestContext())
    Dim dfi = New DataFormItem
    dfi.SetValue("ID", id) 'Add a value for each parameter needed, this report only needed an ID
    Dim req = New ReportsExportRequest With {.ReportId = New Guid("92cc51db-4a6e-4e49-968b-1bb656d12a92"), .ParameterValues = dfi, .ExportType = ExportType.pdf}
    Dim resp = svc.ReportsExport(req) 'This response object has a few properties, one being the bytes of the file

    Let me know if you have any questions!

  • @Nick McGinnis
    Thank you for the response. I had been trying something similar to the VB code you have in C#. It's possible that my parameters are not set right. I'll have to find a much simpler SSRS report that has 1 or no parameters to test. I may not have time now to try this, but I'll try to re-post something later.

Categories