CHAPTER 8 DEPLOYING REPORTS
{
// Strip off the Root name from the path and correct the path separators for
use with SRS
pathName = pathName.Substring(4, pathName.Length - 4);
pathName = pathName.Replace(@"\", "/");
}
byte[] definition = null;
Warning[] warnings = null;
string warningMsg = String.Empty;
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "RDL files (*.rdl)|*.rdl|All files (*.*)|*.*";
openFileDialog.FilterIndex = 1;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
// Read the file and put it into a byte array to pass to SRS
FileStream stream = File.OpenRead(openFileDialog.FileName);
definition = new byte[stream.Length];
stream.Read(definition, 0, (int)(stream.Length));
stream.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
// We are going to use the name of the rdl file as the name of our report
string reportName =
Path.GetFileNameWithoutExtension(openFileDialog.FileName);
reportFile.Text = reportName;
// Now lets use this information to publish the report
try
{
rs.CreateCatalogItem("Report", reportName, pathName, true, definition,
null, out warnings);
if (warnings != null)
{
foreach (Warning warning in warnings)
{
warningMsg += warning.Message + "\n";
}
MessageBox.Show("Report creation failed with the following
warnings:\n" + warningMsg);
}
else
MessageBox.Show(String.Format("Report: {0} created
successfully with no warnings", reportName));