Search results
PDF

Load Bold Report Server reports

You can render the Bold Report Server hosted reports in the Report Viewer easily without creating a Web API service. Bold Report Server provides the built-in Web API service that helps you to display the server reports.

  • Set the Bold Report Server built-in service URL ReportServiceURL and ReportServerUrl, ReportServerCredential, ReportPath to a report deployed on the server. You can use the following complete code in your application to render the Bold Report Server reports.

If you need to know the difference between reportServiceUrl and reportServerUrl, refer to the Difference between Report Service URL and Report Server URL.

this.ReportViewer.ReportServiceURL = @"https://on-premise-demo.boldreports.com/reporting/reportservice/api/Viewer/";
this.ReportViewer.ReportServerUrl = @"https://on-premise-demo.boldreports.com/reporting/api/site/site1";
this.ReportViewer.ServiceAuthorizationToken = GenerateToken("guest@boldreports.com", "demo");
this.ReportViewer.ReportServiceRequestBegin += (sen, arg) =>
    {
        arg.HttpClient.DefaultRequestHeaders.Add("serverurl", "https://on-premise-demo.boldreports.com/reporting/api/site/site1");
    };
this.ReportViewer.ReportPath = @"/Sample Reports/Company Sales";
this.ReportViewer.RefreshReport();

        public string GenerateToken(string userName, string password)
        {
            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                var content = new FormUrlEncodedContent(new[]
                {
                   new KeyValuePair<string, string>("grant_type", "password"),
                   new KeyValuePair<string, string>("username", userName),
                   new KeyValuePair<string, string>("password", password)
                });

                var result = client.PostAsync("https://on-premise-demo.boldreports.com/reporting/api/site/site1/token", content).Result;
                string resultContent = result.Content.ReadAsStringAsync().Result;
                var token = JsonConvert.DeserializeObject<Token>(resultContent);

                return token.token_type + " " + token.access_token;
            }
        }

        public class Token
        {
            public string access_token { get; set; }

            public string token_type { get; set; }

            public string expires_in { get; set; }

            public string userName { get; set; }

            public string serverUrl { get; set; }

            public string password { get; set; }
        }