August 2008 - Posts

In this blog post, Haissam Abdul Malak will explain how to dynamically load a crystal report file into a webform by using the CrystalReportViewer class and how to successfully deploy the application. For instance, suppose you have ".rpt" file in your web application folder and you dynamically want to show it in the page. Below is the code to use

         // Get the filePath
       string filePath = Server.MapPath("~/Reports/report1.rpt");
        // Create new instance of the CrystalReportViewerClass
           CrystalReportViewer rptViewer = new CrystalDecisions.Web.CrystalReportViewer();
       // Create new instance of the Report Document
         ReportDocument rptDoc = new ReportDocument();
      // Load the rpt file into the ReportDocument Class
        rptDoc.Load(filepath);
     // Set the already loaded rpt file into the CrystalReportViewer class
        rptViewer.ReportSource = rptDoc;
    // Add the control to the page
       Page.Form.Controls.Add(rptViewer);

P.S: You should add CrystalDecisions.CrystalReports.Engine and CrystalDecisions.Web and import them.

Now locally it should work because when installing VS 2005, it will install to your local pc all the dlls needed for the crystal report rendering in the GAC . However, you might encounter problems when deploying the application on a web server where the dlls are not installed. One of the solutions is to install the dlls on the web server. You can locate the installer on your local pc at "C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages\CrystalReports". The file name is "CRRedist2005_x86.msi". Run this installer on your webserver and re-run the application.

Hope this helps,

Posted by haissam | with no comments

Lots of ASP.NET developers took advantage of the free ASP.NET RSS toolkit to consume and provide RSS feeds. Thanks to dmitry in a matter of minutes, we will have a nice and robust toolkit which can be intergrated easily in our web application. However, After i finished my application and deploy it on one of our web servers, Consuming RSS stopped working. The error message was "unable to connect to remote server". After investigating and contacting dmitry, i realized our proxy server was rejecting the request. I looked into the open source code provided and knew that the RSS was being loaded directly into an XmlDocument. All we needed is to send an HttpWebRequest, set the proxy configuration, read the response, and finally load the XmlDocument. 

In DownloadManager Class, replace DownloadFeedDom by the below

          //// look for disk cache first
            CacheInfo dom = TryLoadFromDisk(url);

            if (CacheReadable(dom))
            {
                return dom;
            }

            string ttlString = null;
            HttpWebRequest webRequest = null;
            string strResult = null;
            try
            {
                // Create a new web request
                webRequest = WebRequest.Create(url) as HttpWebRequest;
                // Check if ProxyServerUrl in the appSettings is not empty
                if (!string.IsNullOrEmpty(WebConfigurationManager.AppSettings["ProxyServerUrl"].ToString()))
                {
                    // instantiate a new WebProxy class and send the ProxyServerUrl to the contructor parameter
                    System.Net.WebProxy proxy = new System.Net.WebProxy(WebConfigurationManager.AppSettings["ProxyServerUrl"].ToString(), true);
                    // Set the proxy credentials
                    proxy.Credentials = new NetworkCredential(WebConfigurationManager.AppSettings["PassThroughUser"].ToString(), WebConfigurationManager.AppSettings["PassThroughPwd"].ToString());
                    // Set the WebRequest proxy property by the WebProxy class already configured
                    webRequest.Proxy = proxy;
                }
                // Read the response
                using (StreamReader sr = new StreamReader(webRequest.GetResponse().GetResponseStream()))
                {
                    // Set strResult to the response
                    strResult = sr.ReadToEnd();
                }
            }
            catch
            {
            }
            // Load xml From the string
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(strResult);

            if (doc.SelectSingleNode("/rss/channel/ttl") != null)
            {
                ttlString = doc.SelectSingleNode("/rss/channel/ttl").Value;
            }

            //// compute expiry
            int ttlMinutes = GetTtlFromString(ttlString, _defaultTtlMinutes);
            DateTime utcExpiry = DateTime.UtcNow.AddMinutes(ttlMinutes);

            //// save to disk
            return TrySaveToDisk(doc, url, utcExpiry);

P.S: I would like to thank dmitry for his quick response eventhough i know that he would be busy.

Hope this helps,

Posted by haissam | with no comments
The leading UI suite for ASP.NET - Telerik radControls
Outstanding performance. Full ASP.NET AJAX support. Nearly codeless development.