business intelligence consulting
 

Uploading .RDL files using Reporting Services Web Services - Application Integration

by Hans Esquivel 1. October 2012 13:25

This post will demonstrates how to upload an .RDL file to the Reporting Services database. We will begin with creating the method to upload the file and save it to a temporary folder. Next, we then consume the web service method CreateReport to save the .RDL file to the Reporting Services database.

This article assumes you have the following:

  • SQL Server 2008 and Reporting Services installed
  • Microsoft Visual Studio 2008 installed
  • Reporting Services 2008 installed and a configured Report Server
  • Experience with Reporting Services 2005/2008 
  • Experience with ASP.NET and C#
  • Exposure to Web Services

Add Web Form

1) Create a new Web Form and name it "RDLUpload.aspx".

2) Open the RDLUpload.aspx.cs and add the following namespaces:

using System.IO;

using RSIntegrationDemo.RS2005;

using System.Web.Services.Protocols;

 

File Upload 

This section we use the System.Web.UI.WebControls.FileUpload control to upload a file to the temp folder. Next, we pass the string path of the .RDL file saved to the UploadReport method.

            // Specify the path on the server to

            // save the uploaded file to.

            String savePath = HttpContext.Current.Server.MapPath(@"~/Temp/");

 

            // Before attempting to perform operations

            // on the file, verify that the FileUpload

            // control contains a file.

            if (FileUpload1.HasFile)

            {

                // Get the name of the file to upload.

                String fileName = FileUpload1.FileName;

 

                // Append the name of the file to upload to the path.

                savePath += fileName;

 

                // Call the SaveAs method to save the

                // uploaded file to the specified path.

                // This example does not perform all

                // the necessary error checking.              

                // If a file with the same name

                // already exists in the specified path, 

                // the uploaded file overwrites it.

                FileUpload1.SaveAs(savePath);

 

                // Notify the user of the name of the file

                // was saved under.

                string reportExt = fileName.Substring(fileName.Length - 3, 3);

                try

                {

                    // check to ensure the file is type of .rdl

                    if (reportExt == "rdl")

                    {

                        UploadReport(txtReportName.Text, savePath, txtFolderPath.Text, chkOverwrite.Checked);

 

                        lblMessage.Visible = true;

                        lblMessage.Text = "Your file has uploaded successfully.";

                    }

                    else

                    {

                        lblMessage.Text = "Only files extentions of .rdl are allowed.";

                    }

                }

                catch (Exception ex)

                {

                    lblMessage.Text = ex.Message;

                }

            }

            else

            {

                // Notify the user that a file was not uploaded.

                lblMessage.Text = "You did not specify a file to upload.";

            }

Upload Report to Reporting Services database

The method below demonstrates the use of the ReportingService2005.CreateReport for save .RDL files to the Reporting Services database. The CreateReport method requires the following Parameters:

Report
        The name of the new report.
Parent
        The full path name of the parent folder to which to add the report.
Overwrite
        A Boolean expression that indicates whether an existing report with the same name in the location specified should be overwritten.
Definition
        The report definition to publish to the report server.
Properties
         An array of Property[] objects that contains the property names and values to set for the report.

The Definition is your code in the .rdl file and it's a required type of byte[], so we need to use a FileStream object to read the .rdl file - we need to reference the System.IO namespace. After the file is read we can pass the stream to the CreateReport method and save the report to the database. The code below show's how to do this.

        public string UploadReport(string fileName, string filePath, string folderPath, bool overwrite)

        {

            rs = new ReportingService2005();

            rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

 

            Byte[] definition = null;

            Warning[] warnings = null;

 

            try

            {

                FileStream stream = File.OpenRead(filePath);

                definition = new Byte[stream.Length];

                stream.Read(definition, 0, (int)stream.Length);

                stream.Close();

            }

 

            catch (IOException e)

            {

                throw new Exception(e.Message);

            }

 

            try

            {

                warnings = rs.CreateReport(fileName, folderPath, overwrite, definition, null);

 

                if (warnings != null)

                {

                    foreach (Warning warning in warnings)

                    {

                        Console.WriteLine(warning.Message);

                    }

                }

            }

 

            catch (SoapException e)

            {

                return e.Detail.InnerXml.ToString();

            }

 

            return String.Format("Report: {0} created successfully with no warnings", fileName);

        }

 The code is provided as a concept to approaching Reporting Services Web Application Integration and is not recommeded for production use.

Optionally, you may consider using a custom user control to handle this functionality.

Cheers!

Download the code here: RSIntegrationDemo.zip (442.21 kb)

This post will demonstrates how to upload an .RDL file to the Reporting Services database. We will begin with creating the method to upload the file and save it to a temporary folder. Next, we then consume the web service method CreateReport to save the .RDL file to the Reporting Services database.

Reporting Services

Pingbacks and trackbacks (1)+

About Us

InfoToad Consulting provides Data Management and Business Intelligence Solutions and Services. If you would like to learn more about our services or solutons, please visit us at http://www.infotoad.com or call us at (877) 488-0566.

Month List

Tag cloud