public void CreateReport(string reportName, string parentPath, byte[] definition, IEnumerable <string> dataSourcePaths) { Property[] reportProperties = new Property[1]; Property hidden = new Property(); hidden.Name = "Hidden"; hidden.Value = reportName.StartsWith("_") ? "true" : "false"; reportProperties[0] = hidden; _reportService.CreateReport(reportName, parentPath, true, definition, reportProperties); var sources = new List <DataSource>(); foreach (var dataSourcePath in dataSourcePaths) { DataSourceReference dsRef = new DataSourceReference(); dsRef.Reference = dataSourcePath; var ds = new DataSource(); ds.Item = dsRef; sources.Add(ds); } //DataSourceReference dsRef = new DataSourceReference(); // dsRef.Reference = dataSourcePaths; // DataSource[] Sources = _reportService.GetItemDataSources(parentPath + "/" + reportName); if (sources != null && sources.Count > 0) { try { _reportService.SetItemDataSources(parentPath + "/" + reportName, sources.ToArray()); } catch (Exception) { } } }
/// <summary> /// Attaches the data source to report. /// </summary> /// <param name="dataSourceName">Name of the data source.</param> /// <param name="dataSourcePath">The data source path.</param> /// <param name="reportName">Name of the report.</param> /// <param name="reportLocation">The report location.</param> /// <returns></returns> public bool AttachDataSourceToReport(string dataSourceName, string dataSourcePath, string reportName, string reportLocation) { bool resVal; try { string fullReportPath = (reportLocation + "/" + reportName).Replace("//", @"/"); string fullDataSourcePath = (dataSourcePath.Replace(dataSourceName, string.Empty) + dataSourceName).Replace(@"\", @"/"); DataSource[] dataSources = _reportsServerInstance2005.GetItemDataSources(fullReportPath); var dsRef = new DataSourceReference { Reference = fullDataSourcePath }; dataSources[0].Item = dsRef; _reportsServerInstance2005.SetItemDataSources(fullReportPath, dataSources); resVal = true; } catch (Exception) { resVal = false; } return(resVal); }
public static void CreateReport(string reportingServiceUrl, string name, string parent, string[] dataSourcePaths, string definitionFile) { // Open the definition. byte[] definition; using (var stream = File.OpenRead(definitionFile)) { definition = new byte[stream.Length]; stream.Read(definition, 0, (int)stream.Length); stream.Close(); } var service = new ReportingService2005 { Url = reportingServiceUrl, Credentials = System.Net.CredentialCache.DefaultCredentials }; var warnings = service.CreateReport(name, parent, true, definition, null); // If there are data sources then associate them with the report. if (dataSourcePaths != null && dataSourcePaths.Length > 0) { var dataSources = (from dsp in dataSourcePaths select new DataSource { Item = new DataSourceReference { Reference = dsp }, Name = GetName(dsp), }).ToArray(); service.SetItemDataSources(GetPath(name, parent), dataSources); } }
public void CreateReport(string reportName, string parentPath, byte[] definition, string dataSourcePath) { Property[] reportProperties = new Property[1]; Property hidden = new Property(); hidden.Name = "Hidden"; hidden.Value = reportName.StartsWith("_") ? "true" : "false"; reportProperties[0] = hidden; _reportService.CreateReport(reportName, parentPath, true, definition, reportProperties); DataSourceReference dsRef = new DataSourceReference(); dsRef.Reference = dataSourcePath; DataSource[] Sources = _reportService.GetItemDataSources(parentPath + "/" + reportName); if (Sources != null && Sources.Length > 0) { Sources[0].Item = dsRef; try { _reportService.SetItemDataSources(parentPath + "/" + reportName, Sources); } catch (Exception) { } } }
private void UploadReport(ReportItem item) { _Service.CreateReport(item.Name, item.ParentPath, true, item.ReportDefinition, null); var dataSources = GetDataSources(item.DataSources); if (dataSources.Length > 0) { _Service.SetItemDataSources(item.Path, dataSources); } }
public bool AttachDataSourceToReport(string _dataSourceName, string _dataSourcePath, string _report, string _reportLocation) { bool resVal = false; try { string fullReportPath = (_reportLocation + "/" + _report).Replace("//", @"/"); string fullDataSourcePath = (_dataSourcePath.Replace(_dataSourceName, string.Empty) + _dataSourceName).Replace(@"\", @"/"); DataSource[] sharedDs = _reportsServerInstance.GetItemDataSources(fullReportPath); DataSource[] targetDs = new DataSource[sharedDs.Count()]; int counter = 0; foreach (var dataSource in sharedDs) { DataSourceReference dsRef = new DataSourceReference { Reference = fullDataSourcePath }; dataSource.Item = dsRef; targetDs[counter] = dataSource; } _reportsServerInstance.SetItemDataSources(fullReportPath, targetDs); resVal = true; } catch (Exception) { resVal = false; } return(resVal); }
public void SetItemDataSources(string item, string dataSourceName) { var reportDataSources = webserviceProxy.GetItemDataSources(item); foreach (var existingDataSource in reportDataSources) { var dsr = new DataSourceReference { Reference = dataSourceName }; existingDataSource.Item = dsr; } webserviceProxy.SetItemDataSources(item, reportDataSources); }
private void UpdateReportDataSources(string folder, string name, Dictionary <string, DataSourceDefinitionOrReference> dataSources) { var itemPath = $"{folder}/{name}"; var existingDataSources = rs.GetItemDataSources(itemPath); var sources = existingDataSources .Where(ds => dataSources.ContainsKey(ds.Name)) .Select(ds => new DataSource { Name = ds.Name, Item = dataSources[ds.Name] }) .ToArray(); if (sources.Any()) { rs.SetItemDataSources(itemPath, sources); } }
public string SaveReport(string report, Stream file, string name, bool overwrite, ref Guid id) { id = Guid.Empty; string _report = report.ToLower().Replace(".rdl", ""); if (this.CheckExist(ItemTypeEnum.Report, WebConfigurationManager.AppSettings["ReportsRootPath"].ToString(), (name == "" ? _report : name)) == true && overwrite == false) { return("The Report '" + (name == "" ? _report : name) + "' already exists"); } Byte[] definition = null; try { System.IO.BinaryReader br = new System.IO.BinaryReader(file); definition = br.ReadBytes((Int32)file.Length); //Create Report rs.CreateReport((name == string.Empty ? _report : name), WebConfigurationManager.AppSettings["ReportsRootPath"].ToString(), overwrite, definition, null); //Set DataSource DataSourceReference Item1 = new DataSourceReference(); DataSource[] datasources = rs.GetItemDataSources(WebConfigurationManager.AppSettings["ReportsRootPath"].ToString() + "/" + (name == "" ? _report : name)); Item1.Reference = WebConfigurationManager.AppSettings["ReportsRootPath"].ToString() + WebConfigurationManager.AppSettings["MyDataSource"].ToString(); datasources[0].Item = Item1; rs.SetItemDataSources(WebConfigurationManager.AppSettings["ReportsRootPath"].ToString() + "/" + (name == "" ? _report : name), datasources); string _id = GetReportID(WebConfigurationManager.AppSettings["ReportsRootPath"].ToString() + "/" + (name == "" ? _report : name)); id = _id != string.Empty ? new Guid(_id) : Guid.Empty; return(string.Format("Report: {0} created successfully", name == "" ? _report : name)); } catch (Exception ex) { Console.WriteLine(ex.Message); return(ex.Message); } }
private void uploadReport(string destinationPath, string reportName, byte[] reportDef) { try { //Create report destRS.CreateReport(reportName, destinationPath, true, reportDef, null); //Link datasources var reportPath = destinationPath; if (reportPath.EndsWith("/")) { reportPath += reportName; } else { reportPath += "/" + reportName; } var reportDss = destRS.GetItemDataSources(reportPath); List <DataSource> dataSources = new List <DataSource>(); foreach (var reportDs in reportDss) { if (destDS.ContainsKey(reportDs.Name)) { DataSourceReference reference = new DataSourceReference(); reference.Reference = destDS[reportDs.Name]; var ds = new DataSource(); ds.Item = (DataSourceDefinitionOrReference)reference; ds.Name = reportDs.Name; dataSources.Add(ds); } } destRS.SetItemDataSources(reportPath, dataSources.ToArray()); } catch (Exception e) { MessageBox.Show("Upload " + reportName + " failed." + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private string DeployReport(string localPath, string serverPath, string dataSourcePath, string dataSourceName) { byte[] definition = null; Warning[] warnings = null; string retRes = String.Empty; try { // Read the file and put it into a byte array to pass to SRS FileStream stream = File.OpenRead(localPath); 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(localPath); // Now lets use this information to publish the report try { warnings = rs.CreateReport(reportName, serverPath, true, definition, null); if (warnings != null) { retRes = String.Format("Report {0} created with warnings :\n", reportName); foreach (Warning warning in warnings) { retRes += warning.Message + "\n"; } } else { retRes = String.Format("Report {0} created successfully with no warnings\n", reportName); } // check xml datasource var isXmlProvider = IsXmlDataProvider(localPath); if (isXmlProvider) { return(retRes); } //set the datasource DataSourceReference dsr = new DataSourceReference(); dsr.Reference = dataSourcePath + "/" + dataSourceName; DataSource[] dsarray = rs.GetItemDataSources(serverPath + "/" + reportName); DataSource ds = new DataSource(); if (dsarray.Length > 0) { ds = dsarray[0]; ds.Item = (DataSourceReference)dsr; rs.SetItemDataSources(serverPath + "/" + reportName, dsarray); retRes += String.Format("Data source succesfully set to {0}\n", dsr.Reference); } } catch (SoapException ex) { return(String.Format("Report {0} failed with exception {1}\n", reportName, ex.Detail.InnerXml.ToString())); } return(retRes); }
private void UpdateConnections(string destPath, TreeNodeCollection nodes) { foreach (TreeNode node in nodes) { if ((bool)node.Tag) { if (node.Nodes.Count > 0) { var childPath = destPath; if (node.Checked) { if (destPath.Equals(ROOT_FOLDER)) { childPath = ROOT_FOLDER + node.Text; } else { childPath = destPath + PATH_SEPERATOR + node.Text; } } UpdateConnections(childPath, node.Nodes); } else { var itemPath = ROOT_FOLDER + node.FullPath.Replace("\\", PATH_SEPERATOR); var itemType = sourceRS.GetItemType(itemPath); var dataSources = new DataSource[0]; dataSources = sourceRS.GetItemDataSources(itemPath); if (dataSources.Any()) { var dataSource = (DataSourceDefinition)dataSources.First(d => d.Name == dsName).Item; dataSource.CredentialRetrieval = CredentialRetrievalEnum.Store; dataSource.UserName = rptDsUsername; dataSource.Password = rptDsPassword; sourceRS.SetItemDataSources(itemPath, dataSources); } var destReportPath = destPath; if (destReportPath.EndsWith("/")) { destReportPath += node.Text; } else { destReportPath += "/" + node.Text; } processedNodeCount++; bwUpdateConn.ReportProgress(processedNodeCount * 100 / selectedNodeCount); } } } }