Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controlling the SQL Server Reporting Services Report Viewer programmatically

I'm having a problem with the ASP.NET version of the ReportViewer control for SSRS.

In my ASP.NET web forms file I have:

    <rsweb:ReportViewer ID="webViewer" runat="server" Width="100%" Height="100%" 
        ProcessingMode="Remote">
        <ServerReport ReportPath="/AnalyticReports/SiteOverview" 
            ReportServerUrl="http://someserver/ssrs" />
    </rsweb:ReportViewer>

This works fine and dandy as expected.

However, say I want to change the server and report path programmatically. How would I do that?

I tried this:

webViewer.ServerReport.ReportServerUrl = new Uri("http://someserver/ssrs");
webViewer.ServerReport.ReportPath = "/AnalyticReports/SiteOverview";
webViewer.ServerReport.Refresh();

However that doesn't seem to do anything. I even tried adding a webViewer.Reset() but to no avail.

Anyone point me in the right direction?

like image 226
Lloyd Avatar asked Feb 24 '26 02:02

Lloyd


1 Answers

i did this using a property which will get and set the values

public string ReportPathString 
{ get { return ReportViewer1.ServerReport.ReportPath; } 
  set { ReportViewer1.ServerReport.ReportPath = value; } 
}

public string ReportServerUrlString 
{ get { return ReportViewer1.ServerReport.ReportServerUrl.ToString(); } 
  set { ReportViewer1.ServerReport.ReportServerUrl = new Uri(value); } 
}

also while at page_load, i use the following code for setting the credentials

IReportServerCredentials irsc = new ReportServerCredentials("Username", "Password", "Domain");

the class that is use like below

public class ReportServerCredentials : IReportServerCredentials
{
private string _UserName;
private string _PassWord;
private string _DomainName;

public ReportServerCredentials(string UserName, string PassWord, string DomainName)
{
    _UserName = UserName;
    _PassWord = PassWord;
    _DomainName = DomainName;
}

public System.Security.Principal.WindowsIdentity ImpersonationUser
{
    // use default identity
    get { return null; }
}

public ICredentials NetworkCredentials
{
    // use default identity
    get { return new NetworkCredential(_UserName, _PassWord, _DomainName); }
}

public bool GetFormsCredentials(out Cookie authCookie, out string user,
 out string password, out string authority)
{
    authCookie = null;
    user = password = authority = null;
    return false;
}


}

EDIT: just saw the topic is a year old ...

like image 107
Schuere Avatar answered Feb 25 '26 17:02

Schuere



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!