public ReportWarning[] CreateReport(string filename, string destination, bool overwrite, Byte[] definition, string properties) { Warning[] warnings; webserviceProxy.CreateCatalogItem("Report", Path.GetFileNameWithoutExtension(filename), destination, overwrite, definition, null, out warnings); return(warnings != null?Array.ConvertAll(warnings, ConvertSPWarningToReportWarning) : null); }
public bool CreateDataSet(string CURRENT_USER, Int32 CURRENT_REGISTRY_ID, string name, string parent) { bool objReturn = false; XmlSerializer serializer = null; SharedDataSet dataSet = null; MemoryStream stream = null; try { if (!CheckItemExists("DataSet", parent + "/" + name)) { if (rsMain == null) { rsMain = new ReportingService2010() { Url = ReportServiceUrl, Credentials = System.Net.CredentialCache.DefaultCredentials } } ; serializer = new XmlSerializer(typeof(SharedDataSet)); dataSet = new SharedDataSet(CURRENT_REGISTRY_ID); stream = new MemoryStream(); serializer.Serialize(stream, dataSet); byte[] definition = stream.ToArray(); Warning[] warnings = null; LogDetails logDetails = new LogDetails(String.Format("{0}.{1}", System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName, System.Reflection.MethodBase.GetCurrentMethod().Name), CURRENT_USER, CURRENT_REGISTRY_ID); CatalogItem item = rsMain.CreateCatalogItem("DataSet", name, parent, false, definition, null, out warnings); LogManager.LogTiming(logDetails); if (item != null) { objReturn = true; } } else { objReturn = true; } } catch (Exception ex) { LogManager.LogError(ex.Message, String.Format("{0}.{1}", System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName, System.Reflection.MethodBase.GetCurrentMethod().Name), CURRENT_USER, CURRENT_REGISTRY_ID); throw ex; } finally { if (stream != null) { stream.Close(); stream.Dispose(); stream = null; } } return(objReturn); }
private static void CreateReport(ReportingService2010 reportingService, ReportItem report) { if (reportingService == null) { throw new ArgumentNullException("reportingService"); } if (report == null) { throw new ArgumentNullException("report"); } string parent = TesterUtility.GetParentPath(report.Path); ReportingService2010TestEnvironment.CreateFolderFromPath(reportingService, parent); Warning[] warnings; reportingService.CreateCatalogItem("Report", report.Name, parent, true, report.Definition, null, out warnings); }
private static void CreateReports(ReportingService2010 reportingService, string path) { if (reportingService == null) { throw new ArgumentNullException("reportingService"); } if (string.IsNullOrEmpty(path)) { throw new ArgumentException("path"); } foreach (ReportItem report in SetupReportItems) { string fullPath = string.Format(report.Path, path); string parent = TesterUtility.GetParentPath(fullPath); Warning[] warnings; reportingService.CreateCatalogItem("Report", report.Name, parent, true, report.Definition, null, out warnings); } }
public RSCatalogItem CreateCatalogItem(string ItemType, string Name, string Parent, bool Overwrite, [System.Xml.Serialization.XmlElementAttribute(DataType = "base64Binary")] byte[] Definition, RSProperty[] Properties, out RSWarning[] Warnings) { Property[] properties = (Property[])Converter.Convert((object)Properties); Warning[] warns = null; CatalogItem catalog = rs.CreateCatalogItem(ItemType, Name, Parent, Overwrite, Definition, properties, out warns); RSCatalogItem rsCatalog = (RSCatalogItem)Converter.Convert(catalog, typeof(RSCatalogItem)); Warnings = (RSWarning[])Converter.Convert((object)warns); return(rsCatalog); }
private void RestoreRdlFile(string rdlFilePath, string reportingServerUrl, string analysisFolderName, string parentFolderName) { try { CreateFoldersIfNotExists(analysisFolderName, parentFolderName, reportingServerUrl); string rdlName = Path.GetFileNameWithoutExtension(rdlFilePath); string rdlFile = string.Format("/{0}/{1}/{2}", parentFolderName, analysisFolderName, rdlName); using (ReportingService2010 rs = new ReportingService2010()) { rs.Credentials = CredentialCache.DefaultCredentials; rs.Url = string.Format("{0}/ReportService2010.asmx?wsdl", reportingServerUrl); string fileExists = rs.GetItemType(rdlFile); if (fileExists.Equals(parentFolderName, StringComparison.OrdinalIgnoreCase)) { rs.DeleteItem(rdlFile); } FileInfo fileInfo = new FileInfo(rdlFilePath); string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileInfo.FullName); Warning[] warnings = null; byte[] fileContents = File.ReadAllBytes(fileInfo.FullName); string parentPath = string.Format("/{0}/{1}", parentFolderName, analysisFolderName); rs.CreateCatalogItem(itemTypeName, fileNameWithoutExtension, parentPath, true, fileContents, null, out warnings); if (IsWindowsAuthenticated) { RDLDeploy.SetDataSource($"{parentPath}/{fileNameWithoutExtension}", rs); } else { RDLDeploy.SetDataSource($"{parentPath}/{fileNameWithoutExtension}", rs, ReportingServiceUserName, ReportingServicePassword, ReportingServiceExpireTime); } } } catch (NullReferenceException nex) { FailedToRestore(nex.Message); } catch (Exception ex) { FailedToRestore(ex.Message); } }
static void Main(string[] args) { ReportingService2010 rs = new ReportingService2010(); rs.Url = "http://<Server Name>" + "/_vti_bin/ReportServer/ReportService2010.asmx"; rs.Credentials = System.Net.CredentialCache.DefaultCredentials; Byte[] definition = null; Warning[] warnings = null; string name = "MyReport.rdl"; try { FileStream stream = File.OpenRead("MyReport.rdl"); definition = new Byte[stream.Length]; stream.Read(definition, 0, (int)stream.Length); stream.Close(); } catch (IOException e) { Console.WriteLine(e.Message); } try { string parent = "http://<Server Name>/Docs/Documents/"; CatalogItem report = rs.CreateCatalogItem("Report", name, parent, false, definition, null, out warnings); if (warnings != null) { foreach (Warning warning in warnings) { Console.WriteLine(warning.Message); } } else { Console.WriteLine("Report: {0} created successfully " + " with no warnings", name); } } catch (SoapException e) { Console.WriteLine(e.Detail.InnerXml.ToString()); } }
private void DeployReportItems(string Path, string DestinationFolder, string DataSource) { ReportingService2010 rs = new ReportingService2010(); rs.Url = SSRSWS; rs.Credentials = System.Net.CredentialCache.DefaultCredentials; byte[] _reportDefinition; SQL_PTO_Report.localhost.Warning[] _warnings; string strReportPath; FileStream _stream; DataSourceReference reference; DataSource ds; DataSource[] dsarray; string strReportName; System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(Path); foreach (System.IO.FileInfo f in dir.GetFiles("*.rdl")) { strReportPath = f.FullName; _stream = File.OpenRead(strReportPath); _reportDefinition = new Byte[_stream.Length]; _stream.Read(_reportDefinition, 0, (int)_stream.Length); _stream.Close(); strReportName = f.Name.Split('.')[0]; // Create the report into the server. rs.CreateCatalogItem("Report", strReportName, DestinationFolder, true, _reportDefinition, null, out _warnings); dsarray = rs.GetItemDataSources(DestinationFolder + @"/" + strReportName); if (dsarray.Length > 0) { reference = new DataSourceReference(); ds = new DataSource(); reference.Reference = DataSource; ds = dsarray[0]; ds.Item = (DataSourceReference)reference; rs.SetItemDataSources(DestinationFolder + @"/" + strReportName, dsarray); } } rs.Dispose(); }
private void CreateReport(string reportName, string sourceFolder, string targetFolder) { var reportDefinition = GetReportDefinition(reportName, sourceFolder); Warning[] warnings; Log("Creating report '{0}'", reportName); var catalogItem = rs.CreateCatalogItem("Report", reportName, targetFolder, true, reportDefinition, null, out warnings); if (catalogItem == null) { Log("Report '{0}' not created ", reportName); } else { Log("Created report '{0}'", reportName); } PrintWarnings(warnings); }
/// <summary> /// Upload all files on SSRS server using ReportService /// </summary> /// <param name="reportsFolderPath"></param> /// <param name="client"></param> /// <param name="folderName"></param> private static void UploadRdlFiles(string reportsFolderPath, ReportingService2010 client, string folderName) { //Get All Files From Reports Directory var reportFiles = GetReportsFiles(reportsFolderPath); //ConfigurationSettings.AppSettings["ReportsFolderPath"]); foreach (FileInfo fileInfo in reportFiles) { try { FileStream stream = fileInfo.OpenRead(); var definition = new Byte[stream.Length]; stream.Read(definition, 0, (int)stream.Length); stream.Close(); string itemType = "Report"; Property[] prop = null; if (fileInfo.Extension != ".rdl") { itemType = "Resource"; prop = new Property[2]; prop[0] = new Property { Name = "MIMEType", Value = "image/jpeg" }; prop[1] = new Property { Name = "Hidden", Value = "true" }; } //only rdl and jpg needs be published if (fileInfo.Extension == ".rdl" || fileInfo.Extension == ".jpg") { var report = client.CreateCatalogItem(itemType, fileInfo.Name, $"/{folderName}", true, definition, prop, Warnings: out Warning[] warnings); if (report != null) { Console.WriteLine(fileInfo.Name + " Published Successfully "); Console.WriteLine(string.Format("\n")); } if (warnings != null) { foreach (Warning warning in warnings) { Console.WriteLine($"Report: {warning.Message} has warnings"); Console.WriteLine(string.Format("\n")); } } else { Console.WriteLine($"Report: {fileInfo.Name} created successfully with no warnings"); } } Console.WriteLine("\n"); } catch (Exception e) { throw e; } } }
private void browseFile_Click(object sender, EventArgs e) { // Get the full pathname from the treeview control string pathName = ssrsFolders.SelectedNode.FullPath; if (pathName == "Root") { pathName = "/"; } else { // 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)); } } catch (SoapException ex) { MessageBox.Show(ex.Detail.InnerXml.ToString()); } } }