<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tech Insight ! &#187; asp.net</title>
	<atom:link href="http://techinsight.dhanashree.com/category/asp-net/feed/" rel="self" type="application/rss+xml" />
	<link>http://techinsight.dhanashree.com</link>
	<description>Technical blog on ASP.Net, PHP, Web Development, Web hosting , Database Programming</description>
	<lastBuildDate>Fri, 12 Aug 2011 07:26:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>ASP.NET error BC30456: ‘CreateResourceBasedLiteralControl’ is not a member of [file name]</title>
		<link>http://techinsight.dhanashree.com/asp-net-error-bc30456-%e2%80%98createresourcebasedliteralcontrol%e2%80%99-is-not-a-member-of-file-name/</link>
		<comments>http://techinsight.dhanashree.com/asp-net-error-bc30456-%e2%80%98createresourcebasedliteralcontrol%e2%80%99-is-not-a-member-of-file-name/#comments</comments>
		<pubDate>Sat, 05 Feb 2011 10:05:22 +0000</pubDate>
		<dc:creator>jatin</dc:creator>
				<category><![CDATA[.net framework]]></category>
		<category><![CDATA[asp.net]]></category>

		<guid isPermaLink="false">http://techinsight.dhanashree.com/?p=260</guid>
		<description><![CDATA[Recently we came across an error in asp.net web application, on a web server.
error BC30456: ‘CreateResourceBasedLiteralControl’ is not a member of [file name of master page/ control file].
We have tried to find error in many blogs and reputed site, but it did not helped us to solve this issue.
Then we guess it may be error [...]]]></description>
			<content:encoded><![CDATA[<p>Recently we came across an error in asp.net web application, on a web server.</p>
<p>error BC30456: ‘CreateResourceBasedLiteralControl’ is not a member of [file name of master page/ control file].</p>
<p>We have tried to find error in many blogs and reputed site, but it did not helped us to solve this issue.</p>
<p>Then we guess it may be error due to temporary files in .net folder, or reference not updated to recent compiled version of applicaitn.</p>
<p>Finally, it is solved by just <strong>Deleting the directory</strong> in which error was throwing, and then uploading(or copying) same directory  to server and error gone immediately.</p>
<p>Hope, this helps some one facing same error.</p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span style="color: red;" lang="EN-IN"><span style="font-size: 11pt;"><br />
<span style="font-family: Calibri;">NOTE<span style="mso-spacerun: yes;"> </span>: Also visit <a href="http://www.dhanashree.com">www.dhanashree.com</a></span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-IN"><span style="font-size: 11pt; font-family: Calibri;"><br />
If you are in need of any </span><a href="http://dhanashree.com/web-development-services/asp-php-web-development" target="_blank"><span style="font-size: 11pt; font-family: Calibri;">Web Development</span></a><span style="font-size: 11pt; font-family: Calibri;"> feel free to <span style="text-decoration: underline;"><a href="http://dhanashree.com/contact-web-designing-company" target="_blank">Inquire us</a></span> .<span style="mso-spacerun: yes;"> </span><span style="text-decoration: underline;"><a href="http://dhanashree.com/" target="_blank">Dhanashree Inc</a></span>. Expertise in <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/asp-php-web-development/dot-net-web-designing" target="_blank">Asp.net Development</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/asp-php-web-development/lamp-development-php-web-designing" target="_blank">Php Development</a></span>,<span style="mso-spacerun: yes;"> </span><span style="text-decoration: underline;"><br />
<a href="http://dhanashree.com/web-development-services/website-designing" target="_blank">Website designing</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/open-source-wordpress-joomla-oscommerce-customisation" target="_blank">Open Source customisation</a></span>. <span style="text-decoration: underline;"><a href="http://dhanashree.com/" target="_blank">Dhanashree Inc</a> </span>can be our <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/offshore-website-designing-company" target="_blank">offshore development company</a></span> / </span><a href="http://dhanashree.com/web-designing-outsource-advantages" target="_blank"><span style="font-size: 11pt; font-family: Calibri;">outsourcing</span></a><span style="font-size: 11pt; font-family: Calibri;"> <span style="text-decoration: underline;"><a href="http://dhanashree.com/dhanashree-web-development-profile" target="_blank">web development company</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/dedicated-php-dotnet-developer" target="_blank">hire dedicated web programmers</a></span>.</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-IN"><span style="font-size: 11pt; font-family: Calibri;"><br />
Above information is for knowledge sharing<span style="mso-spacerun: yes;"> </span>if you have problem / issue / suggestion please intimate us with details for proper and prompt action.</span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://techinsight.dhanashree.com/asp-net-error-bc30456-%e2%80%98createresourcebasedliteralcontrol%e2%80%99-is-not-a-member-of-file-name/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Read email from SSL enabled POP3 server</title>
		<link>http://techinsight.dhanashree.com/read-email-from-ssl-enabled-pop3-server/</link>
		<comments>http://techinsight.dhanashree.com/read-email-from-ssl-enabled-pop3-server/#comments</comments>
		<pubDate>Thu, 28 Oct 2010 06:58:18 +0000</pubDate>
		<dc:creator>jatin</dc:creator>
				<category><![CDATA[.Net 2.0]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[POP3]]></category>

		<guid isPermaLink="false">http://techinsight.dhanashree.com/?p=240</guid>
		<description><![CDATA[In this article, I will explain you how to read email from POP3 server or read emails from POP3 server which require SSL. Although I have not developed my own library, I prefer to utilize the available resource.
Well, while being in the development, you have very limited time constraint to go and research on POP3 [...]]]></description>
			<content:encoded><![CDATA[<p>In this article, I will explain you how to read email from POP3 server or read emails from POP3 server which require SSL. Although I have not developed my own library, I prefer to utilize the available resource.</p>
<p>Well, while being in the development, you have very limited time constraint to go and research on POP3 and then develop your own component.</p>
<p>It is sometime wise decision to go and do the Googling and find out your requirement.</p>
<p>After all we, as developer should &#8220;do smart work, not hardwork&#8221;.</p>
<p>Anyway, for those who have kind of requirement like reading emails from POP3 server from asp.net, reading email from email server in asp.net etc. Here is the article that you probably find it useful.</p>
<p>Well I had requirement in couple of project where I need to collect emails that are there in particular email&#8217;s Inbox. Earlier I was used to with component &#8220;Indy.Sockets&#8221; component, which really help me to achieve my task.</p>
<p>You may find it from here.</p>
<p><a href="www.indyproject.org/" target="_blank">www.indyproject.org/</a></p>
<p>It is an open source socket library. It supports may protocols like SMTP, POP3, NNTP, HTTP, and many more.</p>
<p>Then in one of the module that I come to develop, I need to read Inbox of a Gmail account…!</p>
<p>Well as you know, Gmail requires SSL.</p>
<p>But the drawback with component is it does not support SSL.</p>
<p>So I discover <a href="http://www.agilecomponents.com/" target="_self">Mailsystem.NET</a>.</p>
<p>MailSystem is a suite of .NET components that provide users with an extensive set of email tools.</p>
<p>I will not explain more in detail on this, rather I will rather just explain how to integrate it and use it.</p>
<p>You can find more information from here..</p>
<p><a href="http://www.agilecomponents.com/" target="_blank">http://www.agilecomponents.com/</a></p>
<p>Once you download it and extract it, you will require to do following steps..</p>
<p>1. Navigate to &#8220;Release&#8221; folder in extracted folder.<br />
2. Find these DLLs: ActiveUp.Net.Mail.dll, ActiveUp.Net.Common.dll, ActiveUp.Net.Dns.dll, ActiveUp.Net.Pop3.dll.<br />
3. Add reference of these DLLs into your project.</p>
<p>Hurray… are almost done with you configuration.</p>
<p>Now, you only just need to develop your script that fetched and read emails from POP3 server.</p>
<p>So for that, here is the readymade script for you J.</p>
<p>public string[] GetSenderEmailsFromPOPServer()</p>
<p>{</p>
<p>Pop3Client pop = new Pop3Client();</p>
<p>System.Collections.Generic.List emails = new System.Collections.Generic.List();</p>
<p>try {</p>
<p>// Connect to the pop3 client</p>
<p>pop.ConnectSsl(SMTPHost, Port, SMTPUserId, SMTPPass);</p>
<p>MessageCollection mc = new MessageCollection();</p>
<p>for (int n = 1; n &lt;= pop.MessageCount; n++) {</p>
<p>Message newMessage = pop.RetrieveMessageObject(n);</p>
<p>//do your stuffs here using newMessage object.</p>
<p>}</p>
<p>} catch (Pop3Exception pexp) {</p>
<p>} finally {</p>
<p>if (pop.IsConnected) {</p>
<p>pop.Disconnect();</p>
<p>}</p>
<p>}</p>
<p>return emails.ToArray();</p>
<p>}</p>
<p>One important part in this script is object initialization.</p>
<p>// Connect to the pop3 client</p>
<p>pop.ConnectSsl(SMTPHost, Port, SMTPUserId, SMTPPass);</p>
<p>As per Gmail, you need to set:</p>
<p>Host: pop.gmail.com</p>
<p>Port: 995</p>
<p>As I told earlier, I want to read email from POP3 server that requires SSL in asp.net.</p>
<p>There are different overloaded constructors that you can use to connect to POP3 server from asp.net.</p>
<p>The library itself is very rich. You can achieve following functionality with POP3 server.</p>
<ul>
<li>Read/Read email from POP3 server in asp.net with CRAM authentication.</li>
<li>Retrieve/Read email from POP3 server in asp.net asynchronously.</li>
<li>Retrieve/Read email from POP3 server in asp.net with secure connection, like SSL in Gmail.</li>
<li>Retrieve/Read only email count from POP3 server in asp.net.</li>
<li>Retrieve/Read only email header from POP3 server in asp.net.</li>
<li>Retrieve/Read full emails from POP3 server in asp.net.</li>
<li>Retrieve/Read full emails to a file from POP3 server in asp.net.</li>
<p>Hope this will be handy to your programming..</p>
<p>Happy programming.</ul>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span style="color: red;" lang="EN-IN"><span style="font-size: 11pt;"><br />
<span style="font-family: Calibri;">NOTE<span style="mso-spacerun: yes;"> </span>: Also visit <a href="http://www.dhanashree.com">www.dhanashree.com</a></span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-IN"><span style="font-size: 11pt; font-family: Calibri;"><br />
If you are in need of any </span><a href="http://dhanashree.com/web-development-services/asp-php-web-development" target="_blank"><span style="font-size: 11pt; font-family: Calibri;">Web Development</span></a><span style="font-size: 11pt; font-family: Calibri;"> feel free to <span style="text-decoration: underline;"><a href="http://dhanashree.com/contact-web-designing-company" target="_blank">Inquire us</a></span> .<span style="mso-spacerun: yes;"> </span><span style="text-decoration: underline;"><a href="http://dhanashree.com/" target="_blank">Dhanashree Inc</a></span>. Expertise in <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/asp-php-web-development/dot-net-web-designing" target="_blank">Asp.net Development</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/asp-php-web-development/lamp-development-php-web-designing" target="_blank">Php Development</a></span>,<span style="mso-spacerun: yes;"> </span><span style="text-decoration: underline;"><br />
<a href="http://dhanashree.com/web-development-services/website-designing" target="_blank">Website designing</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/open-source-wordpress-joomla-oscommerce-customisation" target="_blank">Open Source customisation</a></span>. <span style="text-decoration: underline;"><a href="http://dhanashree.com/" target="_blank">Dhanashree Inc</a> </span>can be our <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/offshore-website-designing-company" target="_blank">offshore development company</a></span> / </span><a href="http://dhanashree.com/web-designing-outsource-advantages" target="_blank"><span style="font-size: 11pt; font-family: Calibri;">outsourcing</span></a><span style="font-size: 11pt; font-family: Calibri;"> <span style="text-decoration: underline;"><a href="http://dhanashree.com/dhanashree-web-development-profile" target="_blank">web development company</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/dedicated-php-dotnet-developer" target="_blank">hire dedicated web programmers</a></span>.</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-IN"><span style="font-size: 11pt; font-family: Calibri;"><br />
Above information is for knowledge sharing<span style="mso-spacerun: yes;"> </span>if you have problem / issue / suggestion please intimate us with details for proper and prompt action.</span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://techinsight.dhanashree.com/read-email-from-ssl-enabled-pop3-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Combine/Compress/Minify JavaScript, CSS in Asp.net</title>
		<link>http://techinsight.dhanashree.com/combinecompressminify-javascript-css-in-asp-net/</link>
		<comments>http://techinsight.dhanashree.com/combinecompressminify-javascript-css-in-asp-net/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 11:00:28 +0000</pubDate>
		<dc:creator>kiran</dc:creator>
				<category><![CDATA[.Net 2.0]]></category>
		<category><![CDATA[.net framework]]></category>
		<category><![CDATA[CSS 3]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Web Developement]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[.net developement]]></category>
		<category><![CDATA[asp.net developement]]></category>
		<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://techinsight.dhanashree.com/combinecompressminify-javascript-css-in-asp-net/</guid>
		<description><![CDATA[Introduction:

When we design and develop the website, the performance is in the core of development. The system you are developing must produce the result with high speed. For the web development perspective, website load performance is very essential thing to take care of. You need good working layout, easy layout and easy navigation.
Here with this [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Introduction:<br />
</strong></p>
<p>When we design and develop the website, the performance is in the core of development. The system you are developing must produce the result with high speed. For the web development perspective, website load performance is very essential thing to take care of. You need good working layout, easy layout and easy navigation.</p>
<p>Here with this article I m not going to talk about of all the aspects of web application performance improvements. But I am specifically targeting the topic when it comes to the CSS and JavaScript faster loading in the client browser.  In fact Google is also counting the speed of your website site when indexing to your website.</p>
<p>The goal was to improve overall performance on the client side. At the same time, it will show how we can force a client side script to be coached at the browser, so that in subsequent visit, it will take those scripts from the cache. This becomes increasingly important when using AJAX techniques within an application that introduce new features and functionality.</p>
<p>First of all I will outline the requirements and essential steps that this project is made of. So that if you want to implement the same in your development, it become easy for you to set up project.</p>
<p>To download complete project, <a href="http://www.esnips.com/doc/bb247398-9971-4fac-bb8e-02a8e8ebad7d/JS-CSS-Combiner-Minifier">click here</a></p>
<p><strong>Setup:<br />
</strong></p>
<p>To begin with, we will have following list of files to be created in the development studio.</p>
<ol>
<li>2 XML files, first one to hold source of JS files for each page and second to  hold CSS files for each page.</li>
<li>A generic class that implement <em>IHttpHandler, </em>that will be used to delivery combined and compressed JavaScript/CSS at the client.</li>
<li>And at last your .ASPX file that will be used to serve combined and compressed Javascript/CSS at client side.</li>
</ol>
<p><strong>Step by Step Implementation:<br />
</strong></p>
<p>Now let&#8217;s get dig into the actual development. To summarize, let&#8217;s say we have a page default.aspx that has following no. of JavaScript files and CSS files. Think of these file that we wanted to combine them and deliver at one go at the client browser.</p>
<ol>
<li>jquery.js</li>
<li>script-file-1.js</li>
<li>style-1.css</li>
<li>style-2.css</li>
</ol>
<p>As you can see, we have 2 different JavaScript file &amp; 2 CSS files. So what basically we will do in the next is to create a utility which can combine given JavaScript and compress it, then send it to client browser. Next the same process will be done for the CSS. Both the CSS files will be combined and compressed and send to client browser.</p>
<p>Now it&#8217;s time to take a look at into actual stuff that does this underlying work.</p>
<p>First of all we will create a CS class file that will hold the programming stuffs.</p>
<p>So perform the following steps to create &amp; configure that CS class file.</p>
<ol>
<li>
<div>Create CS class file with the name <em>ScriptCombiner.cs</em> and put the following code in that.</div>
</li>
</ol>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">public</span><span style="color: blue;"> </span><span style="color: blue;">class</span><br />
<span style="color: #2b91af;">ScriptCombiner</span> : <span style="color: #2b91af;">IHttpHandler<span style="color: #000000;">{</span></span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">private</span><span style="color: blue;"> </span><span style="color: blue;">readonly</span><span style="color: blue;"> </span><span style="color: blue;">static</span><span style="color: blue;"> </span><span style="color: #2b91af;">TimeSpan</span> CACHE_DURATION = <span style="color: #2b91af;">TimeSpan</span>.FromDays(1);</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">private</span><span style="color: blue;"> </span><span style="color: #2b91af;">HttpContext</span> context;</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">public</span><span style="color: blue;"> </span><span style="color: blue;">void</span> ProcessRequest(<span style="color: #2b91af;">HttpContext</span> context){</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">public</span><span style="color: blue;"> </span><span style="color: blue;">bool</span> IsReusable{</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">get</span> { <span style="color: blue;">return</span><span style="color: blue;"> </span><span style="color: blue;">true</span>; }<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;">}</span></p>
<p>As you can see, we are implementing the <span style="color: #2b91af; font-family: Courier New; font-size: 10pt;">IHttpHandler </span>interface.</p>
<p>You can write custom HTTP handlers to process specific, predefined types of HTTP requests in any Common Language Specification (CLS) compliant language. Executable code defined in the HttpHandler classes, rather than conventional ASP or ASP.NET Web pages, responds to these specific requests. HTTP handlers give you a means of interacting with the low-level request and response services of the IIS Web server and provide functionality much like ISAPI extensions but with a simpler programming model.</p>
<p>We are also implementing <span style="font-family: Courier New; font-size: 10pt;">IsReusable </span>properly as it is compulsory to implement as a part of inheritance of <span style="color: #2b91af; font-family: Courier New; font-size: 10pt;">IHttpHandler </span>interface.</p>
<p>Now, let&#8217;s put the nuts &amp; bolts inside the <span style="font-family: Courier New; font-size: 10pt;">ProcessRequest </span>function. I will also explain you the step by step each execution that is inside this function.</p>
<ol>
<li>We will also create another CS class file that is used to compress JavaScript. That file is named as &#8220;JavaScriptMinifier.cs&#8221;. Please take a look at the attached project solution file. As it is contain long lines of code, I can&#8217;t put it here.</li>
<li>Complete your class file with following functions.</li>
</ol>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">public</span><span style="color: blue;"> </span><span style="color: blue;">void</span> ProcessRequest(<span style="color: #2b91af;">HttpContext</span> context)<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">string</span> xStrType, xStrSet, xStrVer, xStrpagecode;</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: #2b91af;">Boolean</span> xBlnCanCompress;</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">this</span>.context = context;</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: #2b91af;">HttpRequest</span> request = context.Request;</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;">xStrType = (!<span style="color: #2b91af;">String</span>.IsNullOrEmpty(request[<span style="color: #a31515;">"type"</span>])) ? request[<span style="color: #a31515;">"type"</span>] : <span style="color: blue;">null</span>;</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> xStrSet = (!<span style="color: #2b91af;">String</span>.IsNullOrEmpty(request[<span style="color: #a31515;">"s"</span>])) ? request[<span style="color: #a31515;">"s"</span>] : <span style="color: blue;">null</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> xStrVer = (!<span style="color: #2b91af;">String</span>.IsNullOrEmpty(request[<span style="color: #a31515;">"v"</span>])) ? request[<span style="color: #a31515;">"v"</span>] : <span style="color: blue;">null</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> xStrpagecode = (!<span style="color: #2b91af;">String</span>.IsNullOrEmpty(request[<span style="color: #a31515;">"pcode"</span>])) ? request[<span style="color: #a31515;">"pcode"</span>] : <span style="color: blue;">null</span>;</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: green;">//first check if client browser can support compressions<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> xBlnCanCompress = CanClientGZip(request);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">using</span> (<span style="color: #2b91af;">MemoryStream</span> memStream = <span style="color: blue;">new</span><span style="color: blue;"> </span><span style="color: #2b91af;">MemoryStream</span>(8092))<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: #2b91af;">Stream</span> writer;</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: green;">//if browser is supporing GZip compression then create a new object using ICSharpCode.SharpZipLib.GZip</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: green;">//library which allow the compressed respose to send to client<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">if</span> (xBlnCanCompress) </span></p>
<p><span style="font-family: Courier New; font-size: 10pt;">writer = (<span style="color: blue;">new</span> ICSharpCode.SharpZipLib.GZip.GZipOutputStream(memStream));</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">else<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> writer = memStream;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">using</span> (writer){</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: green;">//now its time to read all the script/css files into a StringBuilder object.<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: #2b91af;">StringBuilder</span> combinedSource = <span style="color: blue;">new</span><span style="color: blue;"> </span><span style="color: #2b91af;">StringBuilder</span>();<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">foreach</span> (<span style="color: blue;">string</span> file <span style="color: blue;">in</span> GetFileNames(xStrSet, xStrpagecode, xStrType))<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> combinedSource.Append(System.IO.<span style="color: #2b91af;">File</span>.ReadAllText(context.Server.MapPath(file), <span style="color: #2b91af;">Encoding</span>.UTF8));<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: green;">//Upto now we have combined all css/javascript based on request.<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: green;">//its now time to remove extra white spaces and other unwanted characters from respose.</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: green;">//compression will take place now.<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">string</span> minified;</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: green;">//use the YUI Javascript/CSS minifier to compress all js files<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">if</span> (xStrType == <span style="color: #a31515;">&#8220;js&#8221;</span>)<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> minified = combinedSource.ToString();<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">else<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> minified = CompressCSS(combinedSource.ToString());<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: green;">// Send minfied string to output stream<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">byte</span>[] bt = <span style="color: #2b91af;">Encoding</span>.UTF8.GetBytes(minified);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> writer.Write(bt, 0, bt.Length);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: green;">//cache the respose so that in next request it can be reused<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">byte</span>[] responseBytes = memStream.ToArray();<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: green;">//context.Cache.Insert(GetCacheKey(xStrSet, xStrType, xStrVer, xBlnCanCompress), responseBytes, null, System.Web.Caching.Cache.NoAbsoluteExpiration, CACHE_DURATION);<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: green;">// Generate the response<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">this</span>.WriteBytes(responseBytes, xBlnCanCompress, xStrType);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">private</span><span style="color: blue;"> </span><span style="color: blue;">bool</span> CanClientGZip(<span style="color: #2b91af;">HttpRequest</span> request){</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">string</span> acceptEncoding = request.Headers[<span style="color: #a31515;">"Accept-Encoding"</span>];<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">if</span> (!<span style="color: blue;">string</span>.IsNullOrEmpty(acceptEncoding) &amp;&amp;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> (acceptEncoding.Contains(<span style="color: #a31515;">&#8220;gzip&#8221;</span>) || acceptEncoding.Contains(<span style="color: #a31515;">&#8220;deflate&#8221;</span>)))<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">return </span><span style="color: blue;">true</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">return</span><span style="color: blue;"> </span><span style="color: blue;">false</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: green;">// helper method that return an array of file names inside the text file stored in App_Data folder<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">private</span><span style="color: blue;"> </span><span style="color: blue;">static</span><span style="color: blue;"> </span><span style="color: blue;">string</span>[] GetFileNames(<span style="color: blue;">string</span> setName, <span style="color: blue;">string</span> pagecode, <span style="color: blue;">string</span> type)<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {System.Xml.XPath.<span style="color: #2b91af;">XPathDocument</span> doc2;</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> System.Xml.XPath.<span style="color: #2b91af;">XPathNavigator</span> navigator;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> System.Xml.XPath.<span style="color: #2b91af;">XPathNodeIterator</span> iterator;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> System.Collections.Generic.<span style="color: #2b91af;">List</span>&lt;<span style="color: blue;">string</span>&gt; scripts = <span style="color: blue;">new</span> System.Collections.Generic.<span style="color: #2b91af;">List</span>&lt;<span style="color: blue;">string</span>&gt;();<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">string</span> key;</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">if</span> (type == <span style="color: #a31515;">&#8220;js&#8221;</span>)<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> key = <span style="color: #a31515;">&#8220;scriptfile&#8221;</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">else<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> key = <span style="color: #a31515;">&#8220;cssfile&#8221;</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">if</span> (System.Web.<span style="color: #2b91af;">HttpContext</span>.Current.Cache[key] != <span style="color: blue;">null</span>)<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {doc2 = (System.Xml.XPath.<span style="color: #2b91af;">XPathDocument</span>)System.Web.<span style="color: #2b91af;">HttpContext</span>.Current.Cache[key];</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">else<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">string</span> filename;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> filename = System.Web.<span style="color: #2b91af;">HttpContext</span>.Current.Server.MapPath(<span style="color: #2b91af;">String</span>.Format(<span style="color: #a31515;">&#8220;~/App_Data/{0}.xml&#8221;</span>, setName));<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> doc2 = <span style="color: blue;">new</span> System.Xml.XPath.<span style="color: #2b91af;">XPathDocument</span>(filename);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> System.Web.<span style="color: #2b91af;">HttpContext</span>.Current.Cache.Insert(key, doc2, <span style="color: blue;">new</span> System.Web.Caching.<span style="color: #2b91af;">CacheDependency</span>(filename), <span style="color: #2b91af;">DateTime</span>.Now.AddMinutes(60), <span style="color: #2b91af;">TimeSpan</span>.Zero);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;">navigator = doc2.CreateNavigator();</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">if</span> (type == <span style="color: #a31515;">&#8220;js&#8221;</span>)</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;">iterator = navigator.Select(<span style="color: #a31515;">&#8220;/scripts/page[@pagecode='"</span> + pagecode + <span style="color: #a31515;">"']/script&#8221;</span>);</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">else<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> iterator = navigator.Select(<span style="color: #a31515;">&#8220;/styles/page[@pagecode='"</span> + pagecode + <span style="color: #a31515;">"']/style&#8221;</span>);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">while</span> (iterator.MoveNext())<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> scripts.Add(iterator.Current.InnerXml);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">return</span> scripts.ToArray();<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">private</span><span style="color: blue;"> </span><span style="color: blue;">string</span> GetCacheKey(<span style="color: blue;">string</span> type, <span style="color: blue;">string</span> setName, <span style="color: blue;">string</span> version, <span style="color: blue;">bool</span> cancompress)<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">return</span><span style="color: blue;"> </span><span style="color: #a31515;">&#8220;HttpCombiner.&#8221;</span> + setName + <span style="color: #a31515;">&#8220;.&#8221;</span> + type + <span style="color: #a31515;">&#8220;.&#8221;</span> + version + <span style="color: #a31515;">&#8220;.&#8221;</span> + cancompress;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">private</span><span style="color: blue;"> </span><span style="color: blue;">void</span> WriteBytes(<span style="color: blue;">byte</span>[] bytes, <span style="color: blue;">bool</span> isCompressed, <span style="color: blue;">string</span> type)<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: #2b91af;">HttpResponse</span> response = context.Response;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> response.AppendHeader(<span style="color: #a31515;">&#8220;Content-Length&#8221;</span>, bytes.Length.ToString());<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">if</span> (type == <span style="color: #a31515;">&#8220;js&#8221;</span>)<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> response.ContentType = <span style="color: #a31515;">&#8220;application/x-javascript&#8221;</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">else<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> response.ContentType = <span style="color: #a31515;">&#8220;text/css&#8221;</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">if</span> (isCompressed)<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> response.AppendHeader(<span style="color: #a31515;">&#8220;Content-Encoding&#8221;</span>, <span style="color: #a31515;">&#8220;gzip&#8221;</span>);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">else<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> response.AppendHeader(<span style="color: #a31515;">&#8220;Content-Encoding&#8221;</span>, <span style="color: #a31515;">&#8220;utf-8&#8243;</span>);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> context.Response.Cache.SetCacheability(<span style="color: #2b91af;">HttpCacheability</span>.Public);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> context.Response.Cache.SetExpires(<span style="color: #2b91af;">DateTime</span>.Now.Add(CACHE_DURATION));<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> context.Response.Cache.SetMaxAge(CACHE_DURATION);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> response.ContentEncoding = <span style="color: #2b91af;">Encoding</span>.Unicode;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> response.OutputStream.Write(bytes, 0, bytes.Length);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> response.Flush();<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">public</span><span style="color: blue;"> </span><span style="color: blue;">static</span><br />
<span style="color: blue;">string</span> GetScriptTag(<span style="color: blue;">string</span> setname, <span style="color: blue;">string</span> pageid, <span style="color: blue;">string</span> type, <span style="color: blue;">string</span> ver)<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">string</span> result = <span style="color: #a31515;">&#8220;&#8221;</span>;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">if</span> (type == <span style="color: #a31515;">&#8220;js&#8221;</span>)<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> result += <span style="color: #2b91af;">String</span>.Format(<span style="color: #a31515;">&#8220;&lt;script type=\&#8221;text/javascript\&#8221; src=\&#8221;/&#8221;</span> + Web.Utility.Functions.GetURLPrefix() + <span style="color: #a31515;">&#8220;ScriptCombiner.axd?s={0}&amp;v={1}&amp;type=js&amp;pcode={2}\&#8221;&gt;&lt;/script&gt;&#8221;</span>, setname, ver, pageid);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">else<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> result += <span style="color: #2b91af;">String</span>.Format(<span style="color: #a31515;">&#8220;&lt;link link href=\&#8221;ScriptCombiner.axd?s={0}&amp;v={1}&amp;type=css&amp;pcode={2}\&#8221; rel=\&#8221;stylesheet\&#8221; type=\&#8221;text/css\&#8221;/&gt;&#8221;</span>, setname, ver, pageid);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">return</span> result;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">public</span><span style="color: blue;"> </span><span style="color: blue;">static</span><span style="color: blue;"> </span><span style="color: blue;">string</span> CompressCSS(<span style="color: blue;">string</span> body)<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> body = <span style="color: #2b91af;">Regex</span>.Replace(body, <span style="color: #a31515;">&#8220;/\\*.+?\\*/&#8221;</span>, <span style="color: #a31515;">&#8220;&#8221;</span>, <span style="color: #2b91af;">RegexOptions</span>.Singleline);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> body = body.Replace(<span style="color: #a31515;">&#8221;  &#8220;</span>, <span style="color: blue;">string</span>.Empty);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> body = body.Replace(<span style="color: #2b91af;">Environment</span>.NewLine + <span style="color: #2b91af;">Environment</span>.NewLine + <span style="color: #2b91af;">Environment</span>.NewLine, <span style="color: blue;">string</span>.Empty);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> body = body.Replace(<span style="color: #2b91af;">Environment</span>.NewLine + <span style="color: #2b91af;">Environment</span>.NewLine, <span style="color: #2b91af;">Environment</span>.NewLine);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> body = body.Replace(<span style="color: #2b91af;">Environment</span>.NewLine, <span style="color: blue;">string</span>.Empty);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> body = body.Replace(<span style="color: #a31515;">&#8220;\\t&#8221;</span>, <span style="color: blue;">string</span>.Empty);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> body = body.Replace(<span style="color: #a31515;">&#8221; {&#8220;</span>, <span style="color: #a31515;">&#8220;{&#8220;</span>);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> body = body.Replace(<span style="color: #a31515;">&#8221; :&#8221;</span>, <span style="color: #a31515;">&#8220;:&#8221;</span>);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> body = body.Replace(<span style="color: #a31515;">&#8220;: &#8220;</span>, <span style="color: #a31515;">&#8220;:&#8221;</span>);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> body = body.Replace(<span style="color: #a31515;">&#8220;, &#8220;</span>, <span style="color: #a31515;">&#8220;,&#8221;</span>);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> body = body.Replace(<span style="color: #a31515;">&#8220;; &#8220;</span>, <span style="color: #a31515;">&#8220;;&#8221;</span>);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> body = body.Replace(<span style="color: #a31515;">&#8220;;}&#8221;</span>, <span style="color: #a31515;">&#8220;}&#8221;</span>);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> body = <span style="color: #2b91af;">Regex</span>.Replace(body, <span style="color: #a31515;">&#8220;/\\*[^\\*]*\\*+([^/\\*]*\\*+)*/&#8221;</span>, <span style="color: #a31515;">&#8220;$1&#8243;</span>);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> body = <span style="color: #2b91af;">Regex</span>.Replace(body, <span style="color: #a31515;">&#8220;(?&lt;=[&gt;])\\s{2,}(?=[&lt;])|(?&lt;=[&gt;])\\s{2,}(?=&amp;nbsp;)|(?&lt;=&amp;ndsp;)\\s{2,}(?=[&lt;])&#8221;</span>, <span style="color: blue;">string</span>.Empty);<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">return</span> body;<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }</span></p>
<p>You are now almost done with 50% of work for your project.</p>
<p>Now let&#8217;s take a look at the few of important execution steps that are in this function.</p>
<p>First of all we are declaring four different string variables:</p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">string</span> xStrType, xStrSet, xStrVer, xStrpagecode;<br />
</span></p>
<p>They will be used to get the Querystring passed in to this handler. This is utilized later on the code.</p>
<p>Moving next, you will find these function call:</p>
<p><span style="color: green; font-family: Courier New; font-size: 10pt;">//first check if client browser can support compressions<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> xBlnCanCompress = CanClientGZip(request);<br />
</span></p>
<p>This is basically to check does client browser support GZip compression.</p>
<p>Gzip compression, otherwise known as content encoding, is a publicly defined way to compress textual content transferred from web servers to browsers. HTTP compression uses public domain compression algorithms, like gzip and compress, to compress XHTML, JavaScript, CSS, and other text files at the server. This standards-based method of delivering compressed content is built into HTTP 1.1, and most modern browsers that support HTTP 1.1 support ZLIB inflation of deflated documents. In other words, they can decompress compressed files automatically, which saves time and bandwidth.</p>
<p>In the next step it is preparing the <em>stream</em> object used to hold the response output. We will not take dipper look into that code. As I expect that the a beginning developer even must be able know about next few line of code. <span style="font-family: Wingdings;">J</span></p>
<p>Let&#8217;s move to the line of code:</p>
<p><span style="color: green; font-family: Courier New; font-size: 10pt;">//now its time to read all the script/css files into a StringBuilder object.<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><br />
<span style="color: #2b91af;">StringBuilder</span> combinedSource = <span style="color: blue;">new</span><br />
<span style="color: #2b91af;">StringBuilder</span>();<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">foreach</span> (<span style="color: blue;">string</span> file <span style="color: blue;">in</span> GetFileNames(xStrSet, xStrpagecode, xStrType))<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> combinedSource.Append(System.IO.<span style="color: #2b91af;">File</span>.ReadAllText(context.Server.MapPath(file), <span style="color: #2b91af;">Encoding</span>.UTF8));<br />
</span></p>
<p>As you can see in the foreach loop, it is calling to method <span style="font-family: Courier New; font-size: 10pt;">GetFileNames, </span>by passing 3 different parameters. Here this is also core and important part of this project. Let me outline you first what this function basically do. This function will read to the &#8220;script.xml&#8221; file that hold content of script file that we want to load. Please look inside the attached project solution to understand it better. The function will read xml file and return array of string object containing JavaScript files to read.</p>
<p>In the subsequent line of code, it iterate through each file name and read it. Each content of read file is placed inside a <span style="color: #2b91af; font-family: Courier New; font-size: 10pt;">StringBuilder </span>object.</p>
<p>Please take look at the code inside the <span style="font-family: Courier New; font-size: 10pt;">GetFileNames </span>function to understand what is actually happening inside it. It fetches the JavaScript/CSS based on the parameter passed. And return either the JavaScript file name array or CSS file name array.</p>
<p>So now we have a combined script/CSS with us. It&#8217;s a time to minify JavaScript/CSS now.</p>
<p>Following line of code will minify respective JavaScript/CSS based on type of client script requested.</p>
<p><span style="color: green; font-family: Courier New; font-size: 10pt;">//use the YUI Javascript/CSS minifier to compress all js files<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"><br />
<span style="color: blue;">if</span> (xStrType == <span style="color: #a31515;">&#8220;js&#8221;</span>)<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: #2b91af;">JavaScriptMinifier</span> minifier = <span style="color: blue;">new</span><br />
<span style="color: #2b91af;">JavaScriptMinifier</span>();<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> minified = minifier.Minify(combinedSource.ToString());<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> <span style="color: blue;">else<br />
</span></span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> {<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> minified = CompressCSS(combinedSource.ToString());<br />
</span></p>
<p><span style="font-family: Courier New; font-size: 10pt;"> }<br />
</span></p>
<p>The <span style="color: #2b91af; font-family: Courier New; font-size: 10pt;">JavaScriptMinifier </span>has been created in the 2<sup>nd</sup> step. Please refer to the attached solution project for more detail regarding this class file. I have adopted this class file from one of the article</p>
<p>You will also see function <span style="font-family: Courier New; font-size: 10pt;">CompressCSS </span>that is used to compress CSS file. The compressor of CSS file is done through just few regular expression. JavaScript compression has different algorithm.</p>
<p>After that it is calling to <span style="font-family: Courier New; font-size: 10pt;">WriteBytes </span>function that will prepare the combined &amp; compressed JavaScript &amp; CSS response and send it to the client.</p>
<p>Hurray… as part of implementation we are done.</p>
<p>Now it&#8217;s time to check that in action. You can run the project attached here with and check it In live action.</p>
<p>To download complete project, <a href="http://www.esnips.com/doc/bb247398-9971-4fac-bb8e-02a8e8ebad7d/JS-CSS-Combiner-Minifier">click here</a></p>
<p>Let&#8217;s compare the result of two different pages. The first one is with the compressed JavaScript &amp; CSS. The second one is with the normal JavaScript &amp; CSS. We will also see the difference in load time and size of content received.</p>
<p>Response time with compressed JavaScript &amp; CSS.</p>
<p><img src="http://techinsight.dhanashree.com/article-images/040510_1059_CombineComp1.jpg" alt="" /></p>
<p>Response time without compressed JavaScript &amp; CSS.</p>
<p><img src="http://techinsight.dhanashree.com/article-images/040510_1059_CombineComp2.jpg" alt="" /></p>
<p>As you can see from given statistics</p>
<p>With Combined &amp; Compressed JavaScript and CSS ..</p>
<p>Total request: 3</p>
<p>Response size: 16.3 KB</p>
<p>Without Combined &amp; Compressed JavaScript and CSS ..</p>
<p>Total request: 5</p>
<p>Response size: 96 KB</p>
<p>You can clearly see the difference between these two request.</p>
<p>To get more idea open and run the project yourself. That will give you better idea.</p>
<p>Hope you will find it very useful.</p>
<p>Happy coding…. <span style="font-family: Wingdings;">J</span></p>
<p><span style="font-family: Calibri; font-size: 15px; color: #ff0000;">NOTE<span style="mso-spacerun: yes;"> </span>:</span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-IN"><span style="font-size: 11pt; font-family: Calibri;">If you are in need of any </span><a href="http://dhanashree.com/web-development-services/asp-php-web-development" target="_blank"><span style="font-size: 11pt; font-family: Calibri;">Web Development</span></a><span style="font-size: 11pt; font-family: Calibri;"> feel free to <span style="text-decoration: underline;"><a href="http://dhanashree.com/contact-web-designing-company" target="_blank">Inquire us</a></span> .<span style="mso-spacerun: yes;"> </span><span style="text-decoration: underline;"><a href="http://dhanashree.com/" target="_blank">Dhanashree Inc</a></span>. Expertise in <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/asp-php-web-development/dot-net-web-designing" target="_blank">Asp.net Development</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/asp-php-web-development/lamp-development-php-web-designing" target="_blank">Php Development</a></span>,<span style="mso-spacerun: yes;"> </span><span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/website-designing" target="_blank">Website designing</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/open-source-wordpress-joomla-oscommerce-customisation" target="_blank">Open Source customisation</a></span>. <span style="text-decoration: underline;"><a href="http://dhanashree.com/" target="_blank">Dhanashree Inc</a> </span>can be our <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/offshore-website-designing-company" target="_blank">offshore development company</a></span> / </span><a href="http://dhanashree.com/web-designing-outsource-advantages" target="_blank"><span style="font-size: 11pt; font-family: Calibri;">outsourcing</span></a><span style="font-size: 11pt; font-family: Calibri;"> <span style="text-decoration: underline;"><a href="http://dhanashree.com/dhanashree-web-development-profile" target="_blank">web development company</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/dedicated-php-dotnet-developer" target="_blank">hire dedicated web programmers</a></span>.</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-IN"><span style="font-size: 11pt; font-family: Calibri;">Above information is for knowledge sharing<span style="mso-spacerun: yes;"> </span>if you have problem / issue / suggestion please intimate us with details for proper and prompt action.</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span style="color: red;" lang="EN-IN"><span style="font-size: 11pt;"><br />
<span style="font-family: Calibri;">NOTE<span style="mso-spacerun: yes;"> </span>: Also visit <a href="http://www.dhanashree.com">www.dhanashree.com</a></span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-IN"><span style="font-size: 11pt; font-family: Calibri;"><br />
If you are in need of any </span><a href="http://dhanashree.com/web-development-services/asp-php-web-development" target="_blank"><span style="font-size: 11pt; font-family: Calibri;">Web Development</span></a><span style="font-size: 11pt; font-family: Calibri;"> feel free to <span style="text-decoration: underline;"><a href="http://dhanashree.com/contact-web-designing-company" target="_blank">Inquire us</a></span> .<span style="mso-spacerun: yes;"> </span><span style="text-decoration: underline;"><a href="http://dhanashree.com/" target="_blank">Dhanashree Inc</a></span>. Expertise in <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/asp-php-web-development/dot-net-web-designing" target="_blank">Asp.net Development</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/asp-php-web-development/lamp-development-php-web-designing" target="_blank">Php Development</a></span>,<span style="mso-spacerun: yes;"> </span><span style="text-decoration: underline;"><br />
<a href="http://dhanashree.com/web-development-services/website-designing" target="_blank">Website designing</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/open-source-wordpress-joomla-oscommerce-customisation" target="_blank">Open Source customisation</a></span>. <span style="text-decoration: underline;"><a href="http://dhanashree.com/" target="_blank">Dhanashree Inc</a> </span>can be our <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/offshore-website-designing-company" target="_blank">offshore development company</a></span> / </span><a href="http://dhanashree.com/web-designing-outsource-advantages" target="_blank"><span style="font-size: 11pt; font-family: Calibri;">outsourcing</span></a><span style="font-size: 11pt; font-family: Calibri;"> <span style="text-decoration: underline;"><a href="http://dhanashree.com/dhanashree-web-development-profile" target="_blank">web development company</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/dedicated-php-dotnet-developer" target="_blank">hire dedicated web programmers</a></span>.</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-IN"><span style="font-size: 11pt; font-family: Calibri;"><br />
Above information is for knowledge sharing<span style="mso-spacerun: yes;"> </span>if you have problem / issue / suggestion please intimate us with details for proper and prompt action.</span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://techinsight.dhanashree.com/combinecompressminify-javascript-css-in-asp-net/feed/</wfw:commentRss>
		<slash:comments>41</slash:comments>
		</item>
		<item>
		<title>Custom error tracking library in asp.net using XML &amp; C#</title>
		<link>http://techinsight.dhanashree.com/custom-error-tracking-library-in-asp-net-using-xml-c/</link>
		<comments>http://techinsight.dhanashree.com/custom-error-tracking-library-in-asp-net-using-xml-c/#comments</comments>
		<pubDate>Mon, 28 Dec 2009 09:14:01 +0000</pubDate>
		<dc:creator>kiran</dc:creator>
				<category><![CDATA[.Net 2.0]]></category>
		<category><![CDATA[C#.net]]></category>
		<category><![CDATA[Web Developement]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[.net developement]]></category>
		<category><![CDATA[asp.net developement]]></category>

		<guid isPermaLink="false">http://dhanashree.com/techblog/?p=80</guid>
		<description><![CDATA[
Being an asp.net developers we develop a web project and get it completed in a months of time as there are many organizations which works on very tight bound timeline for developing web sites Or web application projects. And delivers the project to client in months of time
While after project delivery if client come up [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>Being an <a href="http://www.dhanashree.com/web-development-services/asp-php-web-development/dot-net-web-designing" target="_blank">asp.net developers</a> we develop a web project and get it completed in a months of time as there are many organizations which works on very tight bound timeline for <a href="http://www.dhanashree.com/web-development-services/website-designing" target="_blank">developing web sites</a> Or <a href="http://www.dhanashree.com/web-development-services/asp-php-web-development" target="_blank">web application</a> projects. And delivers the project to client in months of time</p>
<p>While after project delivery if client come up saying that they are facing problems or <a href="http://www.dhanashree.com/web-development-services/web-software-application-development" target="_blank">application</a> is giving errors, that time it always becomes a headache for a <a href="http://www.dhanashree.com/web-development-services/asp-php-web-development" target="_blank">developer</a> to test each things even whole project sometimes to find a smaller errors (by means of error here we are not talking about logical errors, we talking about exceptions which mostly responsible for errors in the application), there are many exceptions .net framework fires which we never come to find out while debugging or developing the application. Those exceptions never affect directly to the <a href="http://www.dhanashree.com/web-development-services/web-software-application-development" target="_blank">application</a> but each small exception puts the unnecessary load on the server.</p>
<p>Here is the solution to track each and every smallest things happening inside your <a href="http://www.dhanashree.com/web-development-services/asp-php-web-development/dot-net-web-designing" target="_blank">asp.net web application</a>. Which I named as “<strong>Custom error tracking library</strong>”</p>
<p><strong><em>Custom error tracking library</em></strong></p>
<p>Very first question will come is that, what is the core concept for this.</p>
<p>Concept is like we will be maintaining an XML file with a predefined structure which I have built which will contain all the required fields as nodes and subs. Which we call as <strong>errorlog.xml</strong></p>
<p>There will be a CS library file which will track each and every minor errors/exceptions happens inside the <a href="http://www.dhanashree.com/web-development-services/web-software-application-development" target="_blank">application</a> or .net framework and will put the error details inside the XML file.</p>
<p>Once we got CS library ready with us we just have to a simple function with 2 overload methods as per requirement in each <strong>try/catch</strong> blocks of the code and also in <strong>Application_Error </strong>event of <strong>Global.asax</strong> file.</p>
<h3><em>XML File (errorlog.xml)</em></h3>
<p>&lt;?xml version=”1.0″ encoding=”utf-8″?&gt;</p>
<p>&lt;errorlog&gt;</p>
<p>&lt;error&gt;</p>
<p>&lt;datetime&gt;datetime&lt;/datetime&gt;</p>
<p>&lt;filename&gt;filename&lt;/filename&gt;</p>
<p>&lt;classname&gt;classname&lt;/classname&gt;</p>
<p>&lt;methodname&gt;methodname&lt;/methodname&gt;</p>
<p>&lt;errormethod&gt;errormethod&lt;/errormethod&gt;</p>
<p>&lt;messsage&gt;ErrorMessage&lt;/messsage&gt;</p>
<p>&lt;errordetails&gt;Details goes here&lt;/errordetails&gt;</p>
<p>&lt;IP&gt;IP adress&lt;/IP&gt;</p>
<p>&lt;url&gt;URL&lt;/url&gt;</p>
<p>&lt;/error&gt;</p>
<p>&lt;error&gt;</p>
<p><strong>&lt;/</strong><strong>errorlog</strong><strong>&gt;</strong></p>
<p>Root node of XLM file will be <strong>&lt;errorlog&gt;&lt;/errorlog&gt;</strong> inside root node there will be a sub node  <strong>&lt;error&gt;&lt;/error&gt;</strong> which will get duplicated for each error. For each error, library will generate a node will all the below listed details in XML file. Next to last error node. So for each error there will be a seaprate ERROR node.</p>
<p>Each fields of the above XML file is descibed beloe :</p>
<ol>
<li><strong>1. </strong><strong>Datetime : </strong>date and time of the error/exception<strong> </strong></li>
<li><strong>2. </strong><strong>File name : </strong>file name where exception or error happens<strong> </strong></li>
<li><strong>3. </strong><strong>Class name : </strong>classname in which error occurred<strong> </strong></li>
<li><strong>4. </strong><strong>Methodname : </strong>function name where errored<strong> </strong></li>
<li><strong>5. </strong><strong>Errormethod :</strong> name of the function which contains error code.<strong> </strong></li>
<li><strong>6. </strong><strong>Message : </strong>error message/exception message<strong> </strong></li>
<li><strong>7. </strong><strong>Error details: </strong>detailed error description which will show whole<strong>stack trace</strong> of the functional execution.<strong> </strong></li>
<li><strong>8. </strong><strong>IP : </strong>client IP address<strong> </strong></li>
<li><strong>9. </strong><strong>URL : </strong>absolute error ULR<strong> </strong></li>
</ol>
<p><strong> </strong></p>
<p><strong> </strong></p>
<h3><em>CS library</em></h3>
<p>There will be a CS library file where we will write all functionality for error handling and writing errors into XML file.</p>
<p><strong>errorHamdler.cs </strong>file will<strong> </strong>have 2 statis methods named <strong>WriteError(), </strong>there will be 2 overloaded methods for same functions with diff. parameters.</p>
<p><strong>CS file will look as given below. We name it as errorHamdler.cs</strong></p>
<h3>errorHandler.cs</h3>
<p>using System;</p>
<p>using System.Collections.Generic;</p>
<p>using System.Text;</p>
<p>using System.Xml;</p>
<p>using System.Reflection;</p>
<p>using System.Diagnostics;</p>
<p>namespace code_center</p>
<p>{</p>
<p>public class errorHandler</p>
<p>{</p>
<p>string _strErrorMessage, _strDetails, _strClassName, _strMethodName;</p>
<p>DateTime _dtOccuranceTime = new DateTime();</p>
<p>public errorHandler()</p>
<p>{</p>
<p>}</p>
<p>public errorHandler(DateTime time, string className, string methodName, string errorMessage, string details)</p>
<p>{</p>
<p>_dtOccuranceTime = time;</p>
<p>_strClassName = className;</p>
<p>_strDetails = details;</p>
<p>_strErrorMessage = errorMessage;</p>
<p>_strMethodName = methodName;</p>
<p>}</p>
<p>public static void WriteError(Exception ex)</p>
<p>{</p>
<p>WriteError(ex, “”);</p>
<p>}</p>
<p><strong>public static void WriteError(Exception ex, string fileName)</strong></p>
<p>{</p>
<p>XmlDocument doc = new XmlDocument();</p>
<p>string strRootPath = System.Configuration.ConfigurationManager.AppSettings["logfilepath"].ToString();</p>
<p>string xmlPath = System.Web.HttpContext.Current.Server.MapPath(strRootPath);</p>
<p>doc.Load(@xmlPath);</p>
<p>XmlNode newXMLNode, oldXMLNode;</p>
<p>oldXMLNode = doc.ChildNodes[1].ChildNodes[0];</p>
<p>newXMLNode = oldXMLNode.CloneNode(true);</p>
<p>StackTrace stackTrace = new StackTrace();</p>
<p>StackFrame stackFrame = stackTrace.GetFrame(1);</p>
<p>MethodBase methodBase = stackFrame.GetMethod();</p>
<p>newXMLNode.ChildNodes[0].InnerText = DateTime.Now.ToString();</p>
<p>newXMLNode.ChildNodes[1].InnerText = fileName;</p>
<p>newXMLNode.ChildNodes[2].InnerText = methodBase.DeclaringType.FullName;</p>
<p>newXMLNode.ChildNodes[3].InnerText = methodBase.Name;</p>
<p>newXMLNode.ChildNodes[4].InnerText = ex.TargetSite.Name;</p>
<p>newXMLNode.ChildNodes[5].InnerText = ex.Message;</p>
<p>newXMLNode.ChildNodes[6].InnerText = ex.StackTrace;</p>
<p>newXMLNode.ChildNodes[7].InnerText = System.Web.HttpContext.Current.Request.UserHostAddress;</p>
<p>newXMLNode.ChildNodes[8].InnerText = System.Web.HttpContext.Current.Request.Url.OriginalString;</p>
<p>doc.ChildNodes[1].AppendChild(newXMLNode);</p>
<p>doc.Save(@xmlPath);</p>
<p>doc.RemoveAll();</p>
<p>}</p>
<p>}</p>
<p>}</p>
<p>In above code there is a line “string strRootPath = System.Configuration.ConfigurationManager.AppSettings["logfilepath"].ToString();”</p>
<p>We need to give XML file path also where we have placed XML file in the project, so just have to add 1 line in web.config file as given below to store actual XML file path, which will be used in abiove functon.</p>
<h3><em>Code inside web.config</em></h3>
<p>&lt;appSettings&gt;</p>
<p>&lt;add key=”logfilepath” value=”~/errorHandling/errorlog.xml”/&gt;</p>
<p>&lt;/appSettings&gt;</p>
<h1><em>How to use error handler in application</em></h1>
<p>Now everything is ready to be used in real time<a href="http://www.dhanashree.com/web-development-services/web-software-application-development" target="_blank"> application</a>. In each <strong>try/catch</strong>block we have to call</p>
<p><strong>Writeerror()</strong> function as described below .</p>
<h3><em>Code inside Default.aspx.vb</em></h3>
<p>protected void Page_Load(object sender, EventArgs e)</p>
<p>{</p>
<p>try</p>
<p>{</p>
<p>throw new Exception(“Custom error”);</p>
<p>}</p>
<p>catch (Exception ex)</p>
<p>{</p>
<p>Response.Write(ex.Message);</p>
<p><strong>code_center.errorHandler.WriteError(ex, “Default.aspx.vb”);</strong></p>
<p>}</p>
<p>}</p>
<p>Apart from each <strong>try/catch</strong> blocks we will put some code in <strong>Global.asax </strong>file also, as given below.</p>
<p>void Application_Error(object sender, EventArgs e)</p>
<p>{</p>
<p>code_center.errorHandler.WriteError(Server.GetLastError().GetBaseException(), “Global.asax”);</p>
<p>}</p>
<p>The reason behind putting code in Global.asax file is very important and necessory as there might be many exceptions which occurs at application level and canot be tracable in any <strong>try/catch</strong> blocks in any function or events. So anyerror except try/catch blocks will come in this event (Application_Error) and will get inserted intoXML file.</p>
<p>That’s it, we have done with the error handling, and all errors will be tractable from the XML file which is being generated via the error handler.</p>
</div>
<p><span style="text-decoration: underline;"><strong><em><br />
</em></strong></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span style="color: red;" lang="EN-IN"><span style="font-size: 11pt;"><span style="font-family: Calibri;"><br />
NOTE<span style="mso-spacerun: yes;"> </span>:</span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-IN"><span style="font-size: 11pt; font-family: Calibri;">If you are in need of any </span><a href="http://dhanashree.com/web-development-services/asp-php-web-development" target="_blank"><span style="font-size: 11pt; font-family: Calibri;">Web Development</span></a><span style="font-size: 11pt; font-family: Calibri;"> feel free to <span style="text-decoration: underline;"><a href="http://dhanashree.com/contact-web-designing-company" target="_blank">Inquire us</a></span> .<span style="mso-spacerun: yes;"> </span><span style="text-decoration: underline;"><a href="http://dhanashree.com/" target="_blank">Dhanashree Inc</a></span>. Expertise in <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/asp-php-web-development/dot-net-web-designing" target="_blank">Asp.net Development</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/asp-php-web-development/lamp-development-php-web-designing" target="_blank">Php Development</a></span>,<span style="mso-spacerun: yes;"> </span><span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/website-designing" target="_blank">Website designing</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/open-source-wordpress-joomla-oscommerce-customisation" target="_blank">Open Source customisation</a></span>. <span style="text-decoration: underline;"><a href="http://dhanashree.com/" target="_blank">Dhanashree Inc</a> </span>can be our <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/offshore-website-designing-company" target="_blank">offshore development company</a></span> / </span><a href="http://dhanashree.com/web-designing-outsource-advantages" target="_blank"><span style="font-size: 11pt; font-family: Calibri;">outsourcing</span></a><span style="font-size: 11pt; font-family: Calibri;"> <span style="text-decoration: underline;"><a href="http://dhanashree.com/dhanashree-web-development-profile" target="_blank">web development company</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/dedicated-php-dotnet-developer" target="_blank">hire dedicated web programmers</a></span>.</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-IN"><span style="font-size: 11pt; font-family: Calibri;">Above information is for knowledge sharing<span style="mso-spacerun: yes;"> </span>if you have problem / issue / suggestion please intimate us with details for proper and prompt action.</span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://techinsight.dhanashree.com/custom-error-tracking-library-in-asp-net-using-xml-c/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Storing and Retrieving image in SQL server 2005 &amp; asp.net using large value data type &amp; HTTP handler</title>
		<link>http://techinsight.dhanashree.com/storing-and-retrieving-image-in-sql-server-2005-asp-net-using-large-value-data-type-http-handler/</link>
		<comments>http://techinsight.dhanashree.com/storing-and-retrieving-image-in-sql-server-2005-asp-net-using-large-value-data-type-http-handler/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 13:51:13 +0000</pubDate>
		<dc:creator>kiran</dc:creator>
				<category><![CDATA[.Net 2.0]]></category>
		<category><![CDATA[C#.net]]></category>
		<category><![CDATA[SQL server 2005]]></category>
		<category><![CDATA[Web Developement]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[.net developement]]></category>
		<category><![CDATA[asp.net developement]]></category>
		<category><![CDATA[SQL server]]></category>

		<guid isPermaLink="false">http://dhanashree.com/techblog/?p=22</guid>
		<description><![CDATA[ASPX page :
&#60;form id=&#8221;form1&#8243; runat=&#8221;server&#8221;&#62;
&#60;div style=&#8221;padding: 200px;&#8221;&#62;
&#60;asp:Image ID=&#8221;imagebox&#8221; runat=&#8221;server&#8221; ImageUrl=&#8221;~/sql-image-store/image-handler.ashx&#8221; /&#62;
&#60;/div&#62;
&#60;/form&#62;
Handler code: image-handler.ashx 
&#60;%@ WebHandler Language=&#8221;C#&#8221; Class=&#8221;image_handler&#8221; %&#62;
using System;
using System.Web;
using System.IO;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Configuration;
public class image_handler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string xStrCon = System.Configuration.ConfigurationManager.ConnectionStrings["conStrImage"].ConnectionString;
SqlConnection xCon = new SqlConnection(xStrCon);
xCon.Open();
SqlCommand xCom = new SqlCommand(&#8220;select * from images where&#8221;, xCon);
SqlDataAdapter xAda = new SqlDataAdapter(xCom);
DataSet ds = new [...]]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste"><strong><a href="http://www.dhanashree.com/web-development-services/asp-php-web-development/dot-net-web-designing" target="_blank">ASPX</a> page :</strong></div>
<div>&lt;form id=&#8221;form1&#8243; runat=&#8221;server&#8221;&gt;</div>
<div id="_mcePaste">&lt;div style=&#8221;padding: 200px;&#8221;&gt;</div>
<div id="_mcePaste">&lt;asp:Image ID=&#8221;imagebox&#8221; runat=&#8221;server&#8221; ImageUrl=&#8221;~/sql-image-store/image-handler.ashx&#8221; /&gt;</div>
<div id="_mcePaste">&lt;/div&gt;</div>
<div id="_mcePaste">&lt;/form&gt;</div>
<p><strong>Handler code: </strong>image-handler.ashx<strong> </strong></p>
<p>&lt;%@ WebHandler Language=&#8221;C#&#8221; Class=&#8221;image_handler&#8221; %&gt;</p>
<p>using System;</p>
<p>using System.Web;</p>
<p>using System.IO;</p>
<p>using System.Data;</p>
<p>using System.Data.Sql;</p>
<p>using System.Data.SqlClient;</p>
<p>using System.Configuration;</p>
<p>public class image_handler : IHttpHandler</p>
<p>{</p>
<p>public void ProcessRequest(HttpContext context)</p>
<p>{</p>
<p>string xStrCon = System.Configuration.ConfigurationManager.ConnectionStrings["conStrImage"].ConnectionString;</p>
<p>SqlConnection xCon = new SqlConnection(xStrCon);</p>
<p>xCon.Open();</p>
<p>SqlCommand xCom = new SqlCommand(&#8220;select * from images where&#8221;, xCon);</p>
<p>SqlDataAdapter xAda = new SqlDataAdapter(xCom);</p>
<p>DataSet ds = new DataSet();</p>
<p>xAda.Fill(ds);</p>
<p>// Image processing starts</p>
<p>byte[] bytImage = ReadFile(context.Server.MapPath(&#8220;banner.JPG&#8221;));</p>
<p>xCom.CommandText = &#8220;insert into images values(2,&#8217;kensington&#8217;,@imagedata)&#8221;;</p>
<p>xCom.Parameters.Add(new SqlParameter(&#8220;@imagedata&#8221;, (object)bytImage));</p>
<p>xCon.Close();</p>
<p>//Display image from SQL server</p>
<p>byte[] imageData = (byte[])ds.Tables[0].Rows[0][2];</p>
<p>context.Response.Clear();</p>
<p>context.Response.ContentType = &#8220;image/JPEG&#8221;;</p>
<p>context.Response.OutputStream.Write(imageData, 0, imageData.Length);</p>
<p>}</p>
<p>byte[] ReadFile(string sPath)</p>
<p>{</p>
<p>//Initialize byte array with a null value initially.</p>
<p>byte[] data = null;</p>
<p>//Use FileInfo object to get file size.</p>
<p>FileInfo fInfo = new FileInfo(sPath);</p>
<p>long numBytes = fInfo.Length;</p>
<p>//Open FileStream to read file</p>
<p>FileStream fStream = new FileStream(sPath, FileMode.Open, FileAccess.Read);</p>
<p>//Use BinaryReader to read file stream into byte array.</p>
<p>BinaryReader br = new BinaryReader(fStream);</p>
<p>//When you use BinaryReader, you need to supply number of bytes to read from file.</p>
<p>//In this case we want to read entire file. So supplying total number of bytes.</p>
<p>data = br.ReadBytes((int)numBytes);</p>
<p>return data;</p>
<p>}</p>
<p>public bool IsReusable</p>
<p>{</p>
<p>get</p>
<p>{</p>
<p>return false;</p>
<p>}</p>
<p>}</p>
<p>}</p>
<p><span style="text-decoration: underline;"><strong><em><br />
</em></strong></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span style="color: red;" lang="EN-IN"><span style="font-size: 11pt;"><span style="font-family: Calibri;"><br />
NOTE<span style="mso-spacerun: yes;"> </span>:</span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-IN"><span style="font-size: 11pt; font-family: Calibri;">If you are in need of any </span><a href="http://dhanashree.com/web-development-services/asp-php-web-development" target="_blank"><span style="font-size: 11pt; font-family: Calibri;">Web Development</span></a><span style="font-size: 11pt; font-family: Calibri;"> feel free to <span style="text-decoration: underline;"><a href="http://dhanashree.com/contact-web-designing-company" target="_blank">Inquire us</a></span> .<span style="mso-spacerun: yes;"> </span><span style="text-decoration: underline;"><a href="http://dhanashree.com/" target="_blank">Dhanashree Inc</a></span>. Expertise in <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/asp-php-web-development/dot-net-web-designing" target="_blank">Asp.net Development</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/asp-php-web-development/lamp-development-php-web-designing" target="_blank">Php Development</a></span>,<span style="mso-spacerun: yes;"> </span><span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/website-designing" target="_blank">Website designing</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/open-source-wordpress-joomla-oscommerce-customisation" target="_blank">Open Source customisation</a></span>. <span style="text-decoration: underline;"><a href="http://dhanashree.com/" target="_blank">Dhanashree Inc</a> </span>can be our <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/offshore-website-designing-company" target="_blank">offshore development company</a></span> / </span><a href="http://dhanashree.com/web-designing-outsource-advantages" target="_blank"><span style="font-size: 11pt; font-family: Calibri;">outsourcing</span></a><span style="font-size: 11pt; font-family: Calibri;"> <span style="text-decoration: underline;"><a href="http://dhanashree.com/dhanashree-web-development-profile" target="_blank">web development company</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/dedicated-php-dotnet-developer" target="_blank">hire dedicated web programmers</a></span>.</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-IN"><span style="font-size: 11pt; font-family: Calibri;">Above information is for knowledge sharing<span style="mso-spacerun: yes;"> </span>if you have problem / issue / suggestion please intimate us with details for proper and prompt action.</span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://techinsight.dhanashree.com/storing-and-retrieving-image-in-sql-server-2005-asp-net-using-large-value-data-type-http-handler/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Developing custom AD rotator control with multiple Image Mapping using C#.net &amp; XML</title>
		<link>http://techinsight.dhanashree.com/developing-custom-ad-rotator-control-with-multiple-image-mapping-using-c-net-xml/</link>
		<comments>http://techinsight.dhanashree.com/developing-custom-ad-rotator-control-with-multiple-image-mapping-using-c-net-xml/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 07:48:24 +0000</pubDate>
		<dc:creator>kiran</dc:creator>
				<category><![CDATA[.Net 2.0]]></category>
		<category><![CDATA[C#.net]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[.net developement]]></category>
		<category><![CDATA[asp.net developement]]></category>
		<category><![CDATA[Web Developement]]></category>

		<guid isPermaLink="false">http://dhanashree.com/techblog/?p=3</guid>
		<description><![CDATA[We are all familiar with AD rotator control asp.net provides to show rotating/random ads on every page refresh.
But I found a limitation of this control while I needed to develop functionality where AD banners get changed on every page refresh as well as each banners should have multiple links which navigates to diff. URLs ( [...]]]></description>
			<content:encoded><![CDATA[<p>We are all familiar with AD rotator control asp.net provides to show rotating/random ads on every page refresh.</p>
<p>But I found a limitation of this control while I needed to develop functionality where AD banners get changed on every page refresh as well as each banners should have multiple links which navigates to diff. URLs ( multiple image mapping in each AD banners )</p>
<p>As this is not possible with AD rotator I have developed a custom asp.net control which provides all this flexibilities with all AD rotator features.</p>
<p><strong>Basic Concept:</strong></p>
<p>To make the control easy to use &amp; understand we will be keeping the concept of defining Ads same like AD rotator control using XML file.</p>
<p>Control will read the Ad banners from the XML file and render all the details with multiple image mappings in the aspx page.</p>
<p><strong>XML file structure: </strong></p>
<p>First and foremost step is to finalize the XML file structure that to be used in custom control to render the ads on random bases.</p>
<p>XML file will look as given in below sample file.</p>
<p><strong>bannes.xml</strong></p>
<p><strong> </strong></p>
<p>&lt;?xml version=”1.0″ encoding=”utf-8″ ?&gt;</p>
<p>&lt;banbers&gt;</p>
<p>&lt;banner&gt;</p>
<p>&lt;ImageUrl&gt;http://xyz.com/banner1.jpg&lt;/ImageUrl&gt;</p>
<p>&lt;AlternateText&gt;Site1 Main&lt;/AlternateText&gt;</p>
<p>&lt;mappings&gt;</p>
<p>&lt;map&gt;</p>
<p>&lt;left&gt;0&lt;/left&gt;</p>
<p>&lt;top&gt;0&lt;/top&gt;</p>
<p>&lt;right&gt;50&lt;/right&gt;</p>
<p>&lt;bottom&gt;50&lt;/bottom&gt;</p>
<p>&lt;navigateUrl&gt;google.com&lt;/navigateUrl&gt;</p>
<p>&lt;/map&gt;</p>
<p>&lt;/mappings&gt;</p>
<p>&lt;/banner&gt;</p>
<p>&lt;banner&gt;</p>
<p>&lt;ImageUrl&gt;banners/5.jpg&lt;/ImageUrl&gt;</p>
<p>&lt;AlternateText&gt;b5&lt;/AlternateText&gt;</p>
<p>&lt;mappings&gt;</p>
<p>&lt;map&gt;</p>
<p>&lt;left&gt;10&lt;/left&gt;</p>
<p>&lt;top&gt;10&lt;/top&gt;</p>
<p>&lt;right&gt;10&lt;/right&gt;</p>
<p>&lt;bottom&gt;10&lt;/bottom&gt;</p>
<p>&lt;navigateUrl&gt;google.com&lt;/navigateUrl&gt;</p>
<p>&lt;/map&gt;</p>
<p>&lt;map&gt;</p>
<p>&lt;left&gt;25&lt;/left&gt;</p>
<p>&lt;top&gt;25&lt;/top&gt;</p>
<p>&lt;right&gt;25&lt;/right&gt;</p>
<p>&lt;bottom&gt;25&lt;/bottom&gt;</p>
<p>&lt;navigateUrl&gt;google.com&lt;/navigateUrl&gt;</p>
<p>&lt;/map&gt;</p>
<p>&lt;map&gt;</p>
<p>&lt;left&gt;10&lt;/left&gt;</p>
<p>&lt;top&gt;10&lt;/top&gt;</p>
<p>&lt;right&gt;10&lt;/right&gt;</p>
<p>&lt;bottom&gt;10&lt;/bottom&gt;</p>
<p>&lt;navigateUrl&gt;google.com&lt;/navigateUrl&gt;</p>
<p>&lt;/map&gt;</p>
<p>&lt;map&gt;</p>
<p>&lt;left&gt;25&lt;/left&gt;</p>
<p>&lt;top&gt;25&lt;/top&gt;</p>
<p>&lt;right&gt;25&lt;/right&gt;</p>
<p>&lt;bottom&gt;25&lt;/bottom&gt;</p>
<p>&lt;navigateUrl&gt;google.com&lt;/navigateUrl&gt;</p>
<p>&lt;/map&gt;</p>
<p>&lt;map&gt;</p>
<p>&lt;left&gt;10&lt;/left&gt;</p>
<p>&lt;top&gt;10&lt;/top&gt;</p>
<p>&lt;right&gt;10&lt;/right&gt;</p>
<p>&lt;bottom&gt;10&lt;/bottom&gt;</p>
<p>&lt;navigateUrl&gt;google.com&lt;/navigateUrl&gt;</p>
<p>&lt;/map&gt;</p>
<p>&lt;map&gt;</p>
<p>&lt;left&gt;25&lt;/left&gt;</p>
<p>&lt;top&gt;25&lt;/top&gt;</p>
<p>&lt;right&gt;25&lt;/right&gt;</p>
<p>&lt;bottom&gt;25&lt;/bottom&gt;</p>
<p>&lt;navigateUrl&gt;google.com&lt;/navigateUrl&gt;</p>
<p>&lt;/map&gt;</p>
<p>&lt;/mappings&gt;</p>
<p>&lt;/banner&gt;</p>
<p>&lt;/banbers&gt;</p>
<p>Inside main <strong>banners</strong> TAG there will be multiple banners TAG to be added for each AD banner,</p>
<p>Each banner TAG will have child nodes(attributes) as listed below:</p>
<ol>
<li>Image URL – AD image URL to be specified here</li>
<li>Alternate text – alt attribute for image</li>
<li>Mappings  &#8211; list of all mappings with relative  <strong>left-right-top-Bottom </strong> attributes
<ol>
<li>Left – left side relative axis</li>
<li>Right – right side relative axis</li>
<li>Top– Top relative axis</li>
<li>Bottom– Bottom relative axis</li>
<li>Navigate URL – URL to navigate</li>
</ol>
</li>
</ol>
<p><strong>Developing Custom Control:</strong></p>
<p>Now next step is to build a custom asp.net control which will read the above XML structure and renders the data accordingly on ASPX page.</p>
<p><strong>C# code file will be as given below: </strong></p>
<p><strong> </strong></p>
<p><strong>ad-banners.cs</strong></p>
<p><strong> </strong></p>
<p>this control will have 1 public property where the XML file path will be given called</p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p>using System;</p>
<p>using System.Collections.Generic;</p>
<p>using System.ComponentModel;</p>
<p>using System.Text;</p>
<p>using System.Web;</p>
<p>using System.Web.UI;</p>
<p>using System.Web.UI.WebControls;</p>
<p>using System.Xml;</p>
<p>namespace InfoquestLibrary.Controls</p>
<p>{</p>
<p>[DefaultProperty("Text")]</p>
<p>[ToolboxData("&lt;{0}:banner runat=server /&gt;")]</p>
<p>public class banner : System.Web.UI.WebControls.WebControl</p>
<p>{</p>
<p>string _strImageURL, _strXMLpath;</p>
<p>[Bindable(true)]</p>
<p>[Category("Appearance")]</p>
<p>[DefaultValue("")]</p>
<p>[Localizable(true)]</p>
<p>public string ImageURL</p>
<p>{</p>
<p>get { return _strImageURL; }</p>
<p>set { _strImageURL = value; }</p>
<p>}</p>
<p>public string XMLpath</p>
<p>{</p>
<p>get { return _strXMLpath; }</p>
<p>set { _strXMLpath = value; }</p>
<p>}</p>
<p>public override void RenderBeginTag(HtmlTextWriter writer)</p>
<p>{</p>
<p>}</p>
<p>public override void RenderEndTag(HtmlTextWriter writer)</p>
<p>{</p>
<p>}</p>
<p>protected override void RenderContents(HtmlTextWriter output)</p>
<p>{</p>
<p>XmlDocument xDoc = new XmlDocument();</p>
<p>XmlNode xRandomNode;</p>
<p>bool useMapping = true;</p>
<p>int xIntRandomNumber;</p>
<p>Random r = new Random();</p>
<p>xDoc.Load(System.Web.HttpContext.Current.Server.MapPath(this.XMLpath));</p>
<p>xIntRandomNumber = r.Next(xDoc.ChildNodes[1].ChildNodes.Count);</p>
<p>xRandomNode = xDoc.ChildNodes[1].ChildNodes[xIntRandomNumber];</p>
<p>if (xRandomNode.ChildNodes[2].Equals(null))</p>
<p>{</p>
<p>useMapping = false;</p>
<p>}</p>
<p>else</p>
<p>{</p>
<p>if (xRandomNode.ChildNodes[2].ChildNodes.Count == 0)</p>
<p>useMapping = false;</p>
<p>}</p>
<p>if (xRandomNode.HasChildNodes)</p>
<p>{</p>
<p>this.ImageURL = xRandomNode.ChildNodes[0].InnerText;</p>
<p>}</p>
<p>output.AddAttribute(HtmlTextWriterAttribute.Src, this.ImageURL);</p>
<p>if (useMapping)</p>
<p>{</p>
<p>output.AddAttribute(HtmlTextWriterAttribute.Usemap, “#map” + this.ID);</p>
<p>}</p>
<p>output.AddAttribute(HtmlTextWriterAttribute.Border, “none”);</p>
<p>this.AddAttributesToRender(output);</p>
<p>output.RenderBeginTag(HtmlTextWriterTag.Img);</p>
<p>if (useMapping)</p>
<p>{</p>
<p>int xIntMaps, xIntCounter;</p>
<p>xIntMaps = xRandomNode.ChildNodes[2].ChildNodes.Count;</p>
<p>output.AddAttribute(HtmlTextWriterAttribute.Name, “map” + this.ID);</p>
<p>output.AddAttribute(HtmlTextWriterAttribute.Id, “map” + this.ID);</p>
<p>this.AddAttributesToRender(output);</p>
<p>output.RenderBeginTag(HtmlTextWriterTag.Map);</p>
<p>for (xIntCounter = 0; xIntCounter &lt; xIntMaps; xIntCounter++)</p>
<p>{</p>
<p>XmlNode xMap = xRandomNode.ChildNodes[2].ChildNodes[xIntCounter];</p>
<p>if (xMap.HasChildNodes)</p>
<p>{</p>
<p>output.AddAttribute(HtmlTextWriterAttribute.Shape, “rect”);</p>
<p>output.AddAttribute(HtmlTextWriterAttribute.Coords, xMap.ChildNodes[0].InnerText + “,” + xMap.ChildNodes[1].InnerText + “,” + xMap.ChildNodes[2].InnerText + “,” + xMap.ChildNodes[3].InnerText);</p>
<p>output.AddAttribute(HtmlTextWriterAttribute.Href, xMap.ChildNodes[4].InnerText);</p>
<p>output.AddAttribute(HtmlTextWriterAttribute.Title, “”);</p>
<p>output.AddAttribute(HtmlTextWriterAttribute.Alt, “”);</p>
<p>output.RenderBeginTag(HtmlTextWriterTag.Area);</p>
<p>output.RenderEndTag();</p>
<p>}</p>
<p>}</p>
<p>output.RenderEndTag();</p>
<p>}</p>
<p>}</p>
<p>protected override void OnPreRender(EventArgs e)</p>
<p>{</p>
<p>}</p>
<p>}</p>
<p>}</p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong>Using customer control in ASPX page:</strong></p>
<p><strong> </strong></p>
<p>Now we are done with developing customer control with all the required functionality.</p>
<p>And control now ready for use.</p>
<p><strong><em>Registering custom control</em></strong></p>
<p><strong><em> </em></strong></p>
<p>&lt;%@ Register Assembly=”code_center_library” TagPrefix=”TCC” Namespace=”TCC.Controls” %&gt;</p>
<p><strong><em>Defining Custom control in ASPX page</em></strong></p>
<p><strong><em> </em></strong></p>
<p>&lt;TCC:banner ID=”ads” runat=”server” XMLpath=”~/banner-mapping/bannes.xml” /&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://techinsight.dhanashree.com/developing-custom-ad-rotator-control-with-multiple-image-mapping-using-c-net-xml/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

