Click here to Skip to main content
15,905,508 members
Home / Discussions / C#
   

C#

 
AnswerRe: FTP Multiple Files With Progress Pin
Bernhard Hiller20-Sep-16 20:47
Bernhard Hiller20-Sep-16 20:47 
GeneralRe: FTP Multiple Files With Progress Pin
Kevin Marois21-Sep-16 9:13
professionalKevin Marois21-Sep-16 9:13 
GeneralRe: FTP Multiple Files With Progress Pin
Bernhard Hiller21-Sep-16 20:54
Bernhard Hiller21-Sep-16 20:54 
GeneralRe: FTP Multiple Files With Progress Pin
Kevin Marois22-Sep-16 6:07
professionalKevin Marois22-Sep-16 6:07 
AnswerRe: FTP Multiple Files With Progress Pin
Peter_in_278022-Sep-16 15:07
professionalPeter_in_278022-Sep-16 15:07 
SuggestionRe: FTP Multiple Files With Progress Pin
Richard Deeming21-Sep-16 2:51
mveRichard Deeming21-Sep-16 2:51 
GeneralRe: FTP Multiple Files With Progress Pin
Kevin Marois21-Sep-16 9:19
professionalKevin Marois21-Sep-16 9:19 
QuestionIndexOutOfRange Exception When Using Multi Dimensional Array Pin
MadDashCoder20-Sep-16 6:07
MadDashCoder20-Sep-16 6:07 
AnswerRe: IndexOutOfRange Exception When Using Multi Dimensional Array Pin
OriginalGriff20-Sep-16 6:18
mveOriginalGriff20-Sep-16 6:18 
GeneralRe: IndexOutOfRange Exception When Using Multi Dimensional Array Pin
MadDashCoder20-Sep-16 6:40
MadDashCoder20-Sep-16 6:40 
AnswerRe: IndexOutOfRange Exception When Using Multi Dimensional Array Pin
ZurdoDev20-Sep-16 7:40
professionalZurdoDev20-Sep-16 7:40 
GeneralRe: IndexOutOfRange Exception When Using Multi Dimensional Array Pin
OriginalGriff20-Sep-16 8:03
mveOriginalGriff20-Sep-16 8:03 
SuggestionRe: IndexOutOfRange Exception When Using Multi Dimensional Array Pin
Richard Deeming20-Sep-16 8:16
mveRichard Deeming20-Sep-16 8:16 
AnswerRe: IndexOutOfRange Exception When Using Multi Dimensional Array Pin
Gerry Schmitz20-Sep-16 9:15
mveGerry Schmitz20-Sep-16 9:15 
Questionforms and SSO login Pin
V.20-Sep-16 1:19
professionalV.20-Sep-16 1:19 
QuestionSSRS Loop Through Report Datasets and Modify at Runtime Pin
David_4119-Sep-16 9:20
David_4119-Sep-16 9:20 
AnswerRe: SSRS Loop Through Report Datasets and Modify at Runtime Pin
Gerry Schmitz19-Sep-16 10:58
mveGerry Schmitz19-Sep-16 10:58 
GeneralRe: SSRS Loop Through Report Datasets and Modify at Runtime Pin
David_4119-Sep-16 11:13
David_4119-Sep-16 11:13 
GeneralRe: SSRS Loop Through Report Datasets and Modify at Runtime Pin
Gerry Schmitz19-Sep-16 18:05
mveGerry Schmitz19-Sep-16 18:05 
GeneralRe: SSRS Loop Through Report Datasets and Modify at Runtime Pin
David_4120-Sep-16 5:19
David_4120-Sep-16 5:19 
GeneralRe: SSRS Loop Through Report Datasets and Modify at Runtime Pin
Gerry Schmitz20-Sep-16 5:31
mveGerry Schmitz20-Sep-16 5:31 
GeneralRe: SSRS Loop Through Report Datasets and Modify at Runtime Pin
David_4120-Sep-16 7:53
David_4120-Sep-16 7:53 
Thanks. Here is the code which handles modifying the Embeded Dataset to point to a different stored procedure. This code requires that you add a web reference to ReportingService2010.

What this code does not show is the following: Earlier in the code we read the SQL from a stored procedure and allow the user to pick some criteria and add a WHERE clause to the query. The new sql is then saved to a new stored procedure which includes the name of the original stored procedure plus _New.

So the goal here is to get the report to use the _New stored procedures. The datasets are embedded and must be repointed to the _New stored procedures.

The following code runs everything. At this time, the user has selected the report that they want to view.
C#
string LocalPath = "";

           if (DownloadReport(reportViewer1.ServerReport.ReportPath, out LocalPath))
           {
               string newPath = "";
               if (LoopThroughDatasetsXML(LocalPath, out newPath))
               {
                   CreateReports(cbMOE.Text + "_New", newPath, reportViewer1.ServerReport.ReportPath);
               }
           }


C#
private bool DownloadReport(string reportPath, out string LocalFolder)
        {
            bool ret = true;
            ReportingService2010.ReportingService2010 rs = new ReportingService2010.ReportingService2010();
            rs.Url = "http://" + m_dbSettings.serverName + "/" + m_dbSettings.reportDbName + "/ReportService2010.asmx";
            rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
                    
            byte[] reportDefinition = null;
            XmlDocument doc = new XmlDocument();

            try
            {
                reportDefinition = rs.GetItemDefinition(reportPath); // Get the report from the server
                MemoryStream stream = new MemoryStream(reportDefinition);

                //start building the path to save the report to the users computer
                reportPath = reportPath.Replace(@"/", @"\");
                
                LocalFolder = Directory.GetCurrentDirectory();                

                LocalFolder = LocalFolder + @"\TrialData\DataAccess\Reports" + reportPath + ".rdl";
                string Folder = Path.GetDirectoryName(LocalFolder);

                //if the folder doesn't exist, create it
                if (!Directory.Exists(Folder))
                {
                    Directory.CreateDirectory(Folder);
                }

                doc.Load(stream);//convert the document to an xml file
                doc.Save(LocalFolder);//save the document
            }
            catch (Exception ex)
            {
                ret = false;
                MessageBox.Show("Problem saving reports. " + ex.Message);
                throw ex;
            }
            return ret;
        }

        /*
         * DRW 9/20/16
         * Loop through datasets in downloaded rdl and replace stored procedure with _New stored procedure
         * Build List<SP> of dataset names and original stored procedure names
         * Save rdl as original name with _New at the end
         */
        private bool LoopThroughDatasetsXML(string reportPath, out string NewFilename)
        {
            bool ret = true;
            NewFilename = "";
            List<SP> sp = new List<SP>();
            XDocument doc = XDocument.Load(reportPath);
            XNamespace ns = doc.Root.Name.Namespace;

            try
            {
                foreach (XElement xe in doc.Descendants(ns + "DataSet"))
                {
                    SP p = new SP();
                    string commandtext = xe.Element(ns + "Query").Element(ns + "CommandText").Value;
                    xe.Element(ns + "Query").Element(ns + "CommandText").Value = commandtext + "_New";
                    XAttribute a = xe.Attribute("Name");
                    p.SPName = commandtext;
                    p.DatasetName = a.Value;
                    sp.Add(p);
                }
            }
            catch (Exception ex)
            {
                ret = false;
                MessageBox.Show("Problem looping through rdl and updating to _New Stored Procedures.\n\n" + ex.Message);

            }
            if (ret)
            {
                try
                {
                    if (sp.Count > 0)
                    {
                        //set new filename
                        NewFilename = reportPath.Substring(0, reportPath.Length - 4) + "_New.rdl";
                        doc.Save(NewFilename);//save the document
                    }
                }
                catch (Exception ex)
                {
                   ret = false;
                MessageBox.Show("Problem saving modified rdl.\n\n" + ex.Message);                   
                }
            }
            return ret;            
        }

        /*
         * Upload a report from the users computer to the report server.
         * definitionpath is the full path to the report file on the users computer.
         * parentFolder is the parent folder of the report on the report server. The folder that the report will be uploaded to. 
         */
        private void CreateReports(string reportName, string definitionPath, string parentFolder)
        {
            ReportingService2010.ReportingService2010 rsc = new ReportingService2010.ReportingService2010();
            rsc.Credentials = System.Net.CredentialCache.DefaultCredentials;

            rsc.Url = "http://" + m_dbSettings.serverName + "/" + m_dbSettings.reportDbName + "/ReportService2010.asmx";
            Byte[] definition = null;
            ReportingService2010.Warning[] warnings = null;

            try
            { //read the report from the hard drive
                FileStream stream = File.OpenRead(definitionPath);
                definition = new Byte[stream.Length];
                stream.Read(definition, 0, (int)stream.Length);
                stream.Close();
            }

            catch (IOException e)
            {
                MessageBox.Show(e.Message);
            }

            try
            { //upload the report to the server - True means overwrite existing report on the server  
                /*
                 * DRW 1-26-2016 Remove .rdl from filename before uploading to server
                 */
                parentFolder = parentFolder.Replace(cbMOE.Text, "");//strip report name from server report path
                parentFolder = parentFolder.Substring(0, parentFolder.Length - 1); // strip off trailing slash
                reportName = reportName.Replace(".rdl", ""); //strip .rdl from filename
                rsc.CreateCatalogItem("Report", reportName, parentFolder, true, definition, null, out warnings);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Problem uploading report. " + ex.Message);
            }
        }

GeneralRe: SSRS Loop Through Report Datasets and Modify at Runtime Pin
Gerry Schmitz20-Sep-16 8:34
mveGerry Schmitz20-Sep-16 8:34 
GeneralRe: SSRS Loop Through Report Datasets and Modify at Runtime Pin
David_4120-Sep-16 8:39
David_4120-Sep-16 8:39 
GeneralRe: SSRS Loop Through Report Datasets and Modify at Runtime Pin
Gerry Schmitz20-Sep-16 9:43
mveGerry Schmitz20-Sep-16 9:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.