Example #1
0
 public List <String> GetReportDatasources(string path)
 {
     return(webserviceProxy.GetItemDataSources(path)
            .Select(datasource => datasource.Item)
            .OfType <DataSourceReference>()
            .Select(dataSourceReference => dataSourceReference.Reference)
            .ToList());
 }
        /// <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 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)
                {
                }
            }
        }
Example #4
0
        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);
        }
Example #5
0
        private string GetDataSource()
        {
            string itemDataSource = string.Empty;

            try
            {
                using (ReportingService2005 reportsServerInstance = ((ReportServerProperties)(SourceNode.TreeView.Tag)).ReportsServerInstance)
                {
                    itemDataSource = reportsServerInstance.GetItemDataSources(SourceNode.FullPath.Replace(SourceNode.TreeView.Nodes[0].Text, string.Empty).Replace(@"\", @"/"))[0].Name;
                }
            }
            catch { }
            return(itemDataSource);
        }
Example #6
0
        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);
            }
        }
Example #7
0
        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);
            }
        }
        /// <summary>
        /// get report data sources
        /// </summary>
        private void FillDataSource()
        {
            try
            {
                lvDataSource.Items.Clear();

                DataSource[] dataSources = _reportServerProperties2005.GetItemDataSources(_reportPath);
                foreach (DataSource dataSource in dataSources)
                {
                    var dsref = (DataSourceReference)dataSource.Item;
                    var li    = new ListViewItem {
                        Text = dataSource.Name, Tag = dataSource
                    };
                    li.SubItems.Add(dsref.Reference);
                    li.ImageKey = "Database";
                    lvDataSource.Items.Add(li);
                }
            }
            catch
            {
            }
        }
Example #9
0
        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);
            }
        }
Example #10
0
 public DataSource[] GetDataSources(string reportPath)
 {
     return(_reportService.GetItemDataSources(reportPath));
 }
Example #11
0
 private void LoadReport(ReportItem item)
 {
     item.ReportDefinition = _Service.GetReportDefinition(item.Path);
     item.DataSources      = _Service.GetItemDataSources(item.Path);
 }
Example #12
0
        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);
        }
Example #13
0
        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);
                    }
                }
            }
        }