Search results
Suggest a FeaturePDF

How to export the report from Bold Reports Report Server

You can export the report from Bold Reports Server into any format (Excel, PDF, HMTL, PPT CSV, XML and Word) using the Export Report API.

The user must have Read permission for the reports.

Pass the following parameters in the request body.

Report Id - The ID of the report.

Server Path - The relative URL of the report.

Export Type - The desired export format (PDF, Excel, Html, PPT, CSV, XML, or Word).

The access token must be passed in the authorization header. To obtain the access token, use the Authentication API

Here is a sample C# code to illustrate the approach.

Add the following assemblies to the namespace

  • System.Runtime.Serialization.Json
  • System.IO
  • Newtonsoft.Json
  • System.Net
  • System.Collections.Generic
  • System.Text

Refer to the Newtonsoft.Json assembly from the nuget package

public class ApiExportReport
{

   public Guid ReportId { get; set; }

   public string ServerPath { get; set; }

   public string ExportType { get; set; }
}

public class ItemResponse
{
   public bool Status { get; set; }

   public byte[] FileContent { get; set; }

   public string StatusMessage { get; set; }

   public string ApiStatus { get; set; }

}

public static ItemResponse ExportReport()
{
   var BoldReportsURL = "https://demo.example.com"; // Provide your Bold Reports URL
   var itemId = Guid.Parse("b401dfc7-91f8-42a6-9f30-0b3e1323a5cc"); // Provide your Report ID
   var exporttypeId = "PDF";
   var itemRequest = new ApiExportReport
      {
       ReportId = itemId,
       ExportType = exporttypeId
      };
      using (var proxy = new CustomWebClient())
      {
         var ser = new DataContractJsonSerializer(typeof(ApiExportReport));
         var mem = new MemoryStream();
         ser.WriteObject(mem, itemRequest);
         proxy.Headers["Content-type"] = "application/json";
         proxy.Headers["Authorization"] = token.token_type + " " + token.access_token; // token must be passed here
         proxy.Encoding = Encoding.UTF8;
         var data = Encoding.UTF8.GetString(mem.ToArray(), 0, (int)mem.Length);
         try
         {
           var rdata = proxy.UploadString(new Uri(BoldReportsURL + "/reporting/api/site/site1/v1.0/reports/export"), "POST", data);
            var result = JsonConvert.DeserializeObject<ItemResponse>(rdata);
            File.WriteAllBytes("D://Test.pdf", result.FileContent);
            return result;
         }
         catch (WebException ex)
         {
            if (ex.Response is HttpWebResponse)
               {
                  var resp = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
                  dynamic obj = JsonConvert.DeserializeObject(resp);
                  Console.WriteLine(obj);
               }
         }
         return null;
      }
}

class CustomWebClient : WebClient
{
   protected override WebRequest GetWebRequest(Uri uri)
   {
      var request = base.GetWebRequest(uri);
      request.Timeout = 4 * 60 * 1000; //Increase time out
      if (request is HttpWebRequest)
      {
      (request as HttpWebRequest).KeepAlive = false;
      }
      return request;
   }
}