Visual Studio .NET - .rdl file(report file) in asp dotnet 2005 with vb.net

Asked By Aldo Lin Lin on 05-Aug-08 12:36 AM

i want to run the .rdl file(report file)  in asp dotnet 2005 with vb.net

so please send me the coding

Coding... - Atul Shinde replied to Aldo Lin Lin on 05-Aug-08 12:44 AM

Actually there are two types of RDLC Mainly : Local report & Server report
Local report runs at client side & Server report at server side.
 
private void LocalizeReport(LocalReport report)
{
    string virtReportPath = ResolveUrl(report.ReportPath);
    // Load RDLC file. 
    XmlDocument doc = new XmlDocument();
    try
    {
        doc.Load(Server.MapPath(virtReportPath));
    }
    catch (XmlException)
    {
        // TIP: If your web site was published with the updatable option switched off
        // you must copy your reports to the target location manually
        return;
    }
    // Create an XmlNamespaceManager to resolve the default namespace.
    XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
    nsmgr.AddNamespace("nm", "http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition");
    nsmgr.AddNamespace("rd", "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner");
    //Go through the nodes of XML document and localize the text of nodes Value, ToolTip, Label. 
    foreach (string nodeName in new String[] { "Value", "ToolTip", "Label" })
    {
        foreach (XmlNode node in doc.DocumentElement.SelectNodes(String.Format("//nm:{0}[@rd:LocID]", nodeName), nsmgr))
        {
            String nodeValue = node.InnerText;
            if (!String.IsNullOrEmpty(nodeValue) && !nodeValue.StartsWith("="))
            {
                try
                {
                    String localizedValue = (string)HttpContext.GetLocalResourceObject(virtReportPath, node.Attributes["rd:LocID"].Value);
                    if (!String.IsNullOrEmpty(localizedValue))
                    {
                        node.InnerText = localizedValue;
                    }
                }
                catch (InvalidCastException)
                {
                    // if the specified resource is not a String
                }
            }
        }
    }
    report.ReportPath = String.Empty;
    //Load the updated RDLC document into LocalReport object.
    using (StringReader rdlcOutputStream = new StringReader(doc.DocumentElement.OuterXml))
    {
        report.LoadReportDefinition(rdlcOutputStream);
        // TIP: If the loaded report definition contains any subreports, you must call LoadSubreportDefinition
    }
}
 
protected void Page_Load(object sender, EventArgs e)
{
    //...
    ReportViewer reportViewer = new ReportViewer();
    reportViewer.LocalReport.ReportPath = "App_Data/Reports/Report.rdlc";
    // you must run the LocalizeReport function before setting parameters or data sources to the report
    LocalizeReport(reportViewer.LocalReport);
    // set parameters
    reportViewer.LocalReport.SetParameters(...);
    // set datasources
    reportViewer.LocalReport.DataSources.Add(...)
    //...
    form1.Controls.Add(reportViewer);
}

Links

http://www.codeproject.com/KB/aspnet/RDLC_Localization.aspx

See this - Sagar P replied to Aldo Lin Lin on 05-Aug-08 05:28 AM

You can use the Report Viewer control (located in the Toolbox) to do this.

set reportingservice2005 url

set  report server url

set report viewer with report

set report viewer report server url

set  report viewer report path

set parameter

set credentials for report ( and for datasource report using is requires.)

See this code;

// Render the report files with the requested types
      private void DoRender(string dir, string[] files, string[] types)
      {
            string source;
            Report report;
            int index;
            ListDictionary ld;
            string file;

            foreach (string filename in files)
            {
                  // Any parameters?  e.g.  file1.rdl?orderid=5
                  index = filename.LastIndexOf('?');
                  if (index >= 0)
                  {
                        ld = this.GetParmeters(filename.Substring(index));
                        file = filename.Substring(0, index);
                  }
                  else
                  {
                        ld = null;
                        file = filename;
                  }

                  // Obtain the source
                  source = this.GetSource(file);
                  // GetSource is omitted: all it does is read the file.

                  if (source == null)
                        continue// error: process the rest of the files

                  // Compile the report
                  report = this.GetReport(source, file);
                  if (report == null)
                        continue// error: process the rest of the files

                  // Obtain the data passing any parameters
                  report.RunGetData(ld);

                  // Render the report in each of the requested types
                  string fileNoExt;
                  fileNoExt = dir + Path.GetFileNameWithoutExtension(file);

                  foreach (string stype in types)
                  {
                        SaveAs(report, fileNoExt+"."+stype, stype);
                  }
            }     // end foreach files
      }

      // GetParameters creates a list dictionary
      // consisting of a report parameter name and a value.
      private ListDictionary GetParmeters(string parms)
      {
            ListDictionary ld= new ListDictionary();
            if (parms == null)
                  return ld; // dictionary will be empty in this case

            // parms are separated by &
            char[] breakChars = new char[] {'&'};
            string[] ps = parms.Split(breakChars);

            foreach (string p in ps)
            {
                  int iEq = p.IndexOf("=");
                  if (iEq > 0)
                  {
                        string name = p.Substring(0, iEq);
                        string val = p.Substring(iEq+1);
                        ld.Add(name, val);
                  }
            }
            return ld;
      }

      private Report GetReport(string prog, string file)
      {
            // Now parse the file
            RDLParser rdlp;
            Report r;

            try
            {
                  rdlp =  new RDLParser(prog);
                  // RDLParser takes RDL XML and Parse compiles the report

                  r = rdlp.Parse();
                  if (r.rl.MaxSeverity > 0)
                  {
                        // have errors fill out the msgs
                        Console.WriteLine("{0} has the following errors:", file);

                        foreach (string emsg in r.rl.ErrorItems)
                        {
                              Console.WriteLine(emsg);
                              // output message to console
                        }

                        int severity = r.rl.MaxSeverity;
                        r.rl.Reset();
                        if (severity > 4)
                        {
                              r = null; // don't return when severe errors
                              returnCode = 8;
                        }
                  }
            }
            catch(Exception e)
            {
                  r = null;
                  Console.WriteLine(e.Message);
                  returnCode = 8;
            }

            return r;
      }

      // Save the file.  The extension determines the type of file to save.
      // "FileName" Name of the file to be saved to.
      // "ext" Type of file to save.  Should be "pdf", "xml", "html".
      private void SaveAs(Report report, string FileName, string type)
      {
            string ext = type.ToLower();
            OneFileStreamGen sg=null;

            try
            {
                  sg = new OneFileStreamGen(FileName, true);
                  // overwrite with this name

                  switch(ext)
                  {
                        case "pdf":
                          report.RunRender(sg, OutputPresentationType.PDF);
                          break;
                        case "xml":
                          report.RunRender(sg, OutputPresentationType.XML);
                          break;
                        case "html": case "htm":
                          report.RunRender(sg, OutputPresentationType.HTML);
                          break;
                        default:
                          Console.WriteLine("Unsupported file " +
                            "extension '{0}'.  " +
                            "Must be 'pdf', 'xml' or 'html'", type);
                          returnCode = 8;
                          break;
                  }
            }

            catch(Exception e)
            {
                  Console.WriteLine(e.Message);
                  returnCode = 8;
            }
            finally
            {
                  if (sg != null)
                  {
                        sg.CloseMainStream();
                  }
            }
            return;
      }

http://www.codeproject.com/KB/database/rdlproject.aspx

http://www.codeproject.com/KB/aspnet/Microsoft_Dynamic_Reports.aspx

http://www.beansoftware.com/ASP.NET-Tutorials/Using-Crystal-Reports.aspx

http://forums.microsoft.com/TechNet/ShowPost.aspx?PostID=1973243&SiteID=17

http://www.codeproject.com/KB/aspnet/RDLC_Localization.aspx

Best Luck!!!!!!!!!!!!!!!!!!!!!
Sujit.