<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Paresh Jagatia's Weblog</title>
	<atom:link href="http://pareshjagatia.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://pareshjagatia.wordpress.com</link>
	<description>Coolest things on ASP.NET Web developement...</description>
	<lastBuildDate>Mon, 05 May 2008 06:53:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='pareshjagatia.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Paresh Jagatia's Weblog</title>
		<link>http://pareshjagatia.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://pareshjagatia.wordpress.com/osd.xml" title="Paresh Jagatia&#039;s Weblog" />
	<atom:link rel='hub' href='http://pareshjagatia.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Export ReportViewer Report to PDF, Excel, HTML</title>
		<link>http://pareshjagatia.wordpress.com/2008/05/03/export-reportviewer-report-to-pdf-excel/</link>
		<comments>http://pareshjagatia.wordpress.com/2008/05/03/export-reportviewer-report-to-pdf-excel/#comments</comments>
		<pubDate>Sat, 03 May 2008 07:08:12 +0000</pubDate>
		<dc:creator>pareshjagatia</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[SSRS - Sql Server Reporting Services]]></category>

		<guid isPermaLink="false">http://pareshjagatia.wordpress.com/?p=12</guid>
		<description><![CDATA[The following code helps exporting the Report into PDF and Excel formats using the Render method of the ServerReport. Use below code after the report is loaded (refresh() is called on the reportviewer control). 1 string mimeType; 2  string encoding; 3  string fileNameExtension; 4  Warning[] warnings; 5  string[] streamids; 6  byte[] exportBytes = reportViewer.ServerReport.Render(&#8220;PDF&#8220;, null, out [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pareshjagatia.wordpress.com&amp;blog=3629307&amp;post=12&amp;subd=pareshjagatia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The following code helps exporting the Report into PDF and Excel formats using the Render method of the ServerReport. Use below code after the report is loaded (refresh() is called on the reportviewer control).</p>
<div><span style="color:#008080;">1</span> <span style="color:#0000ff;">string</span><span style="color:#000000;"> mimeType;<br />
</span><span style="color:#008080;">2</span><span style="color:#000000;">  </span><span style="color:#0000ff;">string</span><span style="color:#000000;"> encoding;<br />
</span><span style="color:#008080;">3</span><span style="color:#000000;">  </span><span style="color:#0000ff;">string</span><span style="color:#000000;"> fileNameExtension;<br />
</span><span style="color:#008080;">4</span><span style="color:#000000;">  Warning[] warnings;<br />
</span><span style="color:#008080;">5</span><span style="color:#000000;">  </span><span style="color:#0000ff;">string</span><span style="color:#000000;">[] streamids;<br />
</span><span style="color:#008080;">6</span><span style="color:#000000;">  </span><span style="color:#0000ff;">byte</span><span style="color:#000000;">[] exportBytes </span><span style="color:#000000;">=</span><span style="color:#000000;"> reportViewer.ServerReport.Render(<span style="color:#800000;">&#8220;<span>PDF</span><span>&#8220;</span></span>, </span><span style="color:#0000ff;">null</span><span style="color:#000000;">, </span><span style="color:#0000ff;">out</span><span style="color:#000000;"> mimeType, </span><span style="color:#0000ff;">out</span><span style="color:#000000;"> encoding, </span><span style="color:#0000ff;">out</span><span style="color:#000000;"> fileNameExtension, </span><span style="color:#0000ff;">out</span><span style="color:#000000;"> streamids, </span><span style="color:#0000ff;">out</span><span style="color:#000000;"> warnings);<br />
</span><span style="color:#008080;">7</span><span style="color:#000000;">  HttpContext.Current.Response.Buffer </span><span style="color:#000000;">=</span><span style="color:#000000;"> </span><span style="color:#0000ff;">true</span><span style="color:#000000;">;<br />
</span><span style="color:#008080;">8</span><span style="color:#000000;">  HttpContext.Current.Response.Clear();<br />
</span><span style="color:#008080;">9</span><span style="color:#000000;">  HttpContext.Current.Response.ContentType </span><span style="color:#000000;">=</span><span style="color:#000000;"> mimeType;<br />
</span><span style="color:#008080;">10</span><span style="color:#000000;">  HttpContext.Current.Response.AddHeader(</span><span style="color:#800000;">&#8220;</span><span style="color:#800000;">content-disposition</span><span style="color:#800000;">&#8220;</span><span style="color:#000000;">, </span><span style="color:#800000;">&#8220;</span><span style="color:#800000;">attachment; filename=ExportedReport.</span><span style="color:#800000;">&#8220;</span><span style="color:#000000;"> </span><span style="color:#000000;">+</span><span style="color:#000000;"> fileNameExtension);<br />
</span><span style="color:#008080;">11</span><span style="color:#000000;">  HttpContext.Current.Response.BinaryWrite(exportBytes);<br />
</span><span style="color:#008080;">12</span><span style="color:#000000;">  HttpContext.Current.Response.Flush();<br />
</span><span style="color:#008080;">13</span><span style="color:#000000;">  HttpContext.Current.Response.End();</span></div>
<p> </p>
<div>To get Excel file use <span style="color:#800000;">&#8220;<span>Excel</span><span>&#8221; <span style="color:#000000;">as the parameter in the Render method.</span></span></span></div>
<div><span style="color:#000000;"><span>Sometimes you might need to send the Report content into email. To Achieve this you can use the above code where you need to pass <span style="color:#800000;">&#8220;<span>HTML4.0</span><span>&#8221; <span style="color:#000000;">as the first parameter to the Render method. After you get the byte array from the Render method you can convert it to string as below</span></span></span></span></span></div>
<p> </p>
<div><span style="color:#008080;">2</span><span style="color:#000000;">  </span><span style="color:#008080;">1</span> <span style="color:#0000ff;">string</span><span style="color:#000000;"> mimeType;<br />
</span><span style="color:#008080;">2</span><span style="color:#000000;">  </span><span style="color:#0000ff;">string</span><span style="color:#000000;"> encoding;<br />
</span><span style="color:#008080;">3</span><span style="color:#000000;">  Warning[] warnings;<br />
</span><span style="color:#008080;">4</span><span style="color:#000000;">  </span><span style="color:#0000ff;">string</span><span style="color:#000000;">[] streamids;<br />
</span><span style="color:#008080;">5</span><span style="color:#000000;">  </span><span style="color:#0000ff;">string</span><span style="color:#000000;"> fileNameExtension;<br />
</span><span style="color:#008080;">6</span><span style="color:#000000;">  </span><span style="color:#0000ff;">byte</span><span style="color:#000000;">[] htmlBytes </span><span style="color:#000000;">=</span><span style="color:#000000;"> PerksReportViewer.ServerReport.Render(</span><span style="color:#800000;">&#8220;</span><span style="color:#800000;">HTML4.0</span><span style="color:#800000;">&#8220;</span><span style="color:#000000;">, </span><span style="color:#0000ff;">null</span><span style="color:#000000;">, </span><span style="color:#0000ff;">out</span><span style="color:#000000;"> mimeType, </span><span style="color:#0000ff;">out</span><span style="color:#000000;"> encoding, </span><span style="color:#0000ff;">out</span><span style="color:#000000;"> fileNameExtension, </span><span style="color:#0000ff;">out</span><span style="color:#000000;"> streamids, </span><span style="color:#0000ff;">out</span><span style="color:#000000;"> warnings);<br />
</span><span style="color:#008080;">7</span><span style="color:#000000;">  </span><span style="color:#0000ff;">string</span><span style="color:#000000;"> reportHtml </span><span style="color:#000000;">=</span><span style="color:#000000;"> System.Text.Encoding.UTF8.GetString(htmlBytes);<br />
</span><span style="color:#008080;">8</span><span style="color:#000000;">  </span><span style="color:#0000ff;">return</span><span style="color:#000000;"> reportHtml;</span></div>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/pareshjagatia.wordpress.com/12/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/pareshjagatia.wordpress.com/12/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pareshjagatia.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pareshjagatia.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pareshjagatia.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pareshjagatia.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pareshjagatia.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pareshjagatia.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pareshjagatia.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pareshjagatia.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pareshjagatia.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pareshjagatia.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pareshjagatia.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pareshjagatia.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pareshjagatia.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pareshjagatia.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pareshjagatia.wordpress.com&amp;blog=3629307&amp;post=12&amp;subd=pareshjagatia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pareshjagatia.wordpress.com/2008/05/03/export-reportviewer-report-to-pdf-excel/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a064eb30504534be34d39fe0d74ac1ac?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pareshjagatia</media:title>
		</media:content>
	</item>
		<item>
		<title>Save HTTP 404</title>
		<link>http://pareshjagatia.wordpress.com/2008/05/01/save-http-404/</link>
		<comments>http://pareshjagatia.wordpress.com/2008/05/01/save-http-404/#comments</comments>
		<pubDate>Thu, 01 May 2008 14:09:00 +0000</pubDate>
		<dc:creator>pareshjagatia</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[FavIcon]]></category>
		<category><![CDATA[HTTP 404]]></category>

		<guid isPermaLink="false">http://pareshjagatia.wordpress.com/2008/05/01/save-http-404/</guid>
		<description><![CDATA[Once I had a call from my boss saying &#8220;Can you tell me if we have used any Favicon file in our website in any page or somewhere? As if we have used it, the file is not in place. Look at this IIS log it is full of 404s for the same file.&#8221;. And [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pareshjagatia.wordpress.com&amp;blog=3629307&amp;post=8&amp;subd=pareshjagatia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div><span style="font-family:verdana;">Once I had a call from my boss saying &#8220;Can you tell me if we have used any Favicon file in our website in any page or somewhere? As if we have used it, the file is not in place. Look at this IIS log it is full of 404s for the same file.&#8221;. And I was absolutely blank about this name. I opened the project and fired &#8220;Find in solution&#8221; but did not get any FavIcon reference.</span></div>
<p> </p>
<div><span style="font-family:verdana;">Huh, a file that is not referenced anywhere in your website and still your IIS has 404 enteries? Later on I came to know that this is the file that is being shown into the address bar and in the favourites list in most browsers. More information about FavIcon can be found </span><a href="http://www.favicon.com/"><span style="font-family:verdana;">here</span></a>.</div>
<p> </p>
<div><span style="font-family:verdana;">And be sure to keep the Favicon file small in size to avoid high bandwidth usage, check this out on <a href="http://www.hanselman.com/blog/FavIconicoCanBeABandwidthHog.aspx">Scott&#8217;s Blog</a>. <span style="font-family:verdana;">But keep this file atleast to save 404 in your IIS log. One other file is </span></span><a href="http://www.robotstxt.org/"><span style="font-family:verdana;">Robots.txt</span></a><span style="font-family:verdana;"> that, I am not pretty sure, puts 404 in your IIS log when not found by the crawlers. You can check it out.</span></div>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/pareshjagatia.wordpress.com/8/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/pareshjagatia.wordpress.com/8/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pareshjagatia.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pareshjagatia.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pareshjagatia.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pareshjagatia.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pareshjagatia.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pareshjagatia.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pareshjagatia.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pareshjagatia.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pareshjagatia.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pareshjagatia.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pareshjagatia.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pareshjagatia.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pareshjagatia.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pareshjagatia.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pareshjagatia.wordpress.com&amp;blog=3629307&amp;post=8&amp;subd=pareshjagatia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pareshjagatia.wordpress.com/2008/05/01/save-http-404/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a064eb30504534be34d39fe0d74ac1ac?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pareshjagatia</media:title>
		</media:content>
	</item>
		<item>
		<title>Safer Email Address</title>
		<link>http://pareshjagatia.wordpress.com/2008/05/01/safer-email-address/</link>
		<comments>http://pareshjagatia.wordpress.com/2008/05/01/safer-email-address/#comments</comments>
		<pubDate>Thu, 01 May 2008 13:21:00 +0000</pubDate>
		<dc:creator>pareshjagatia</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://pareshjagatia.wordpress.com/2008/05/01/safer-email-address/</guid>
		<description><![CDATA[There are email capture programs that grabs email addresses from web pages. Even you can write one for you using the WebClient and from the ResponseText put the regular expression to capture email. Now a days there are some tools that makes you image for your email address to make your email address safe from [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pareshjagatia.wordpress.com&amp;blog=3629307&amp;post=7&amp;subd=pareshjagatia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>There are email capture programs that grabs email addresses from web pages. Even you can write one for you using the WebClient and from the ResponseText put the regular expression to capture email.</p>
<p>Now a days there are <a title="some tools" href="http://safemail.justlikeed.net/">some tools</a> that makes you image for your email address to make your email address safe from the above kind of programs. But the solution is when the text is controlled by you. What if you are having a Content Management Solution and people are creating pages using the HTML editors and they put email address into the editor? Or say you have a lot of email addresses to convert, its a headache.</p>
<p>Let us not allow the email capture programs to grab text email addresses from our websites.</p>
<p>Please refer to this post on my another <a title="Blog Post" href="http://pareshjagatia.blogspot.com/2008/05/safer-email-address.html">Post</a> on the Blogger. As the ascii encoded text in the example is not working with the HTML Editor used in the WordPress post writer.</p>
<p> <span style="font-family:verdana;"><span style="font-family:verdana;">Happy Programming&#8230;!!!</span></span></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/pareshjagatia.wordpress.com/7/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/pareshjagatia.wordpress.com/7/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pareshjagatia.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pareshjagatia.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pareshjagatia.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pareshjagatia.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pareshjagatia.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pareshjagatia.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pareshjagatia.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pareshjagatia.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pareshjagatia.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pareshjagatia.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pareshjagatia.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pareshjagatia.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pareshjagatia.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pareshjagatia.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pareshjagatia.wordpress.com&amp;blog=3629307&amp;post=7&amp;subd=pareshjagatia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pareshjagatia.wordpress.com/2008/05/01/safer-email-address/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a064eb30504534be34d39fe0d74ac1ac?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pareshjagatia</media:title>
		</media:content>
	</item>
		<item>
		<title>VIEWSTATE Serialization</title>
		<link>http://pareshjagatia.wordpress.com/2008/04/30/viewstate-serialization/</link>
		<comments>http://pareshjagatia.wordpress.com/2008/04/30/viewstate-serialization/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 13:55:00 +0000</pubDate>
		<dc:creator>pareshjagatia</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[VIEWSTATE]]></category>

		<guid isPermaLink="false">http://pareshjagatia.wordpress.com/2008/04/30/viewstate-serialization/</guid>
		<description><![CDATA[The most important thing for an end user of a website is the how fast the page loads and our responsibility is to make them happy. Frequent thing to achieve this is to review the code and write the code such a way that it performs better (in terms of processing time) but what after [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pareshjagatia.wordpress.com&amp;blog=3629307&amp;post=6&amp;subd=pareshjagatia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="font-family:verdana;">The most important thing for an end user of a website is the how fast the page loads and our responsibility is to make them happy.</p>
<p style="font-family:verdana;">Frequent thing to achieve this is to review the code and write the code such a way that it performs better (in terms of processing time) but what after this ?</p>
<p style="font-family:verdana;">What if we still can increase the page serving speed. Apart from the code performance it is the ISP&#8217;s speed and the size of the page that affects the download speed for a web page.</p>
<p style="font-family:verdana;"></p>
<p style="font-family:verdana;">what if we can decrease the size of the page to some extent ( the size generated after the server side scripting finishes ( i mean the final rendered output)</p>
<p style="font-family:verdana;">for every server control if it&#8217;s ViewState is enabled the data is kept in a viewstate in some encoded format(base64 encoded string as everyone says.)</p>
<p style="font-family:verdana;">wo when showing a control on a page keeps data in the rendered output of control as well in the viewstate along with the</p>
<p style="font-family:verdana;">state ( previous state) information ( doubles the size of final rendered output..!!)</p>
<p style="font-family:verdana;">straighaway coming to the topic we can have this <a href="http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/Truly-Understanding-Viewstate.aspx" target="_blank">VIEWSTATE</a> buddy help us remotely ( not being rendered with the page so by decreasing the final rendered page out put size)</p>
<p style="font-family:verdana;">This can be done keeping the <a href="http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/Truly-Understanding-Viewstate.aspx" target="_blank">VIEWSTATE</a> in the session or keep it at the server. I am keeping it at the web server as I have got the access to the web server and I have developed one web service that deletes files(holding the <a href="http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/Truly-Understanding-Viewstate.aspx" target="_blank">VIEWSTATE</a> on the web server) after a day. In short its upto you to write code into the <strong>SaveViewState</strong> and <strong>GetViewState</strong> methods.</p>
<p style="font-family:verdana;">try the following code snippet ( just paste it in the code behind file of your aspx page)</p>
<div dir="ltr" align="left" style="font-family:verdana;"><span class="249403112-31082005"><span style="font-family:courier new;"><span style="font-size:85%;"><span style="color:#3366ff;">protected override object</span> LoadPageStateFromPersistenceMedium()<br />{<br /><span style="color:#3366ff;">object</span> _objViewState;<br /><span style="color:#3366ff;">string</span> _strViewState;<br />_strViewState = GetViewState();<br />LosFormatter _lFormater = <span style="color:#3366ff;">new</span> LosFormatter();<br /><span style="color:#3366ff;">try</span><br />{<br />//if(_strViewState!=String.Empty)<br />_objViewState = _lFormater.Deserialize(_strViewState);<br />//else<br />//_objViewState=&#8221;";<br />}<br /><span style="color:#3366ff;">catch</span>{<br /><span style="color:#3366ff;">throw new</span> HttpException(&#8220;Invalid ViewState&#8221;);<br />}<br /><span style="color:#3366ff;">return</span> _objViewState;<br />}<br /><span style="color:#3366ff;">protected override void</span> SavePageStateToPersistenceMedium(<span style="color:#3366ff;">object</span> viewState)<br />{<br />StringBuilder _sBuilder = <span style="color:#3366ff;">new</span> StringBuilder();<br />StringWriter _sWriter = new StringWriter(_sBuilder);<br />LosFormatter _lFormater = new LosFormatter();<br />_lFormater.Serialize(_sWriter,viewState);<br />_sWriter.Close();<br />SaveViewState(_sBuilder.ToString());<br />}<br /></span></span></span><span class="249403112-31082005"><span style="font-family:courier new;"><span style="font-size:85%;"><span style="color:#3366ff;">#region</span> Save and Get ViewStateData<br /><span style="color:#3366ff;">private void</span> SaveViewState(<span style="color:#3366ff;">string</span> _vState)<br />{</span></span></span></div>
<div dir="ltr" align="left" style="font-family:verdana;"><span style="font-family:courier new;font-size:85%;">// keep identicle files user-wise ( byadding sessionid) and page wise (for different pages by aading this.toString())</span><span class="249403112-31082005" style="font-family:courier new;font-size:85%;"><br /><span style="color:#3366ff;">string</span> _file = @Request.ServerVariables["APPL_PHYSICAL_PATH"]+Session.SessionID+this.ToString()+&#8221;.txt&#8221;;<br />FileStream _fS = new FileStream(_file,System.IO.FileMode.OpenOrCreate,System.IO.FileAccess.ReadWrite,System.IO.FileShare.ReadWrite);<br />StreamWriter _sW = new StreamWriter(_fS);<br />_sW.Write(_vState);<br />_sW.Close();<br />_fS.Close();<br />}<br /><span style="color:#3366ff;">private string</span> GetViewState()<br />{<br />string _file = @Request.ServerVariables["APPL_PHYSICAL_PATH"]+Session.SessionID+this.ToString()+&#8221;.txt&#8221;;<br />string _retValue=String.Empty;<br />if(File.Exists(_file))<br />{<br />StreamReader _sRead = new StreamReader(_file);<br />_retValue= _sRead.ReadToEnd();<br />_sRead.Close();<br />}<br /><span style="color:#3366ff;">return</span> _retValue;<br />}</span></div>
<p style="font-family:verdana;">happy programming&#8230;&#8230;&#8230;.</p>
<p style="font-family:verdana;">one more thing not to forget if you are using above code and storing the <a href="http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/Truly-Understanding-Viewstate.aspx" target="_blank">VIEWSTATE</a> on web server in files.</p>
<p style="font-family:verdana;">keep a code in your Session_End in the global.asax.cs file (works when your Session State uses InProc mode) to remove the above files to keep the web-server tension free !!!</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/pareshjagatia.wordpress.com/6/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/pareshjagatia.wordpress.com/6/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pareshjagatia.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pareshjagatia.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pareshjagatia.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pareshjagatia.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pareshjagatia.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pareshjagatia.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pareshjagatia.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pareshjagatia.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pareshjagatia.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pareshjagatia.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pareshjagatia.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pareshjagatia.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pareshjagatia.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pareshjagatia.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pareshjagatia.wordpress.com&amp;blog=3629307&amp;post=6&amp;subd=pareshjagatia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pareshjagatia.wordpress.com/2008/04/30/viewstate-serialization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a064eb30504534be34d39fe0d74ac1ac?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pareshjagatia</media:title>
		</media:content>
	</item>
		<item>
		<title>C# Pre Processor Directives</title>
		<link>http://pareshjagatia.wordpress.com/2008/04/30/c-pre-processor-directives-2/</link>
		<comments>http://pareshjagatia.wordpress.com/2008/04/30/c-pre-processor-directives-2/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 09:34:00 +0000</pubDate>
		<dc:creator>pareshjagatia</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[C# Pre Processor Directives]]></category>

		<guid isPermaLink="false">http://pareshjagatia.wordpress.com/2008/04/30/c-pre-processor-directives-2/</guid>
		<description><![CDATA[One of the good features of C# that we rarely use are the Pre Processor directives. Let&#8217;s see how we can use them for us. In general practice, we always write some test code in the application. As in JavaScript we use temporary alerts, in C# code behind too (or even in class library project) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pareshjagatia.wordpress.com&amp;blog=3629307&amp;post=5&amp;subd=pareshjagatia&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style="font-size:9px;">One of the good features of C# that we rarely use are the Pre Processor directives. Let&#8217;s see how we can use them for us.</span>
<p><span style="font-size:9px;">In general practice, we always write some test code in the application. As in JavaScript we use temporary alerts, in C# code behind too (or even in class library project) we use test code like temporary emailing and writing hardcode emails in the application emails. And very often this kind of code goes to production machine that is undesirable as well disastrous. To avoid this we can use the conditional compilation directives. Let&#8217;s see how to use them</span></p>
</p>
<p><span style="font-size:9px;">We are going to use three directives <span style="color:blue;">#define</span>, <span style="color:blue;">#if</span>, <span style="color:blue;">#endif</span>. We can define the symbol in a file using the <span style="color:blue;">#define</span> directive like</span>
</p>
<p><span style="font-size:9px;color:blue;">#define</span><span style="font-size:9px;"> TESTCODE (this will define a symbol named TESTCODE)</span></p>
<p><span style="font-size:9px;">And then we can write our test code within the conditional compilation <span style="color:blue;">#if</span> directive as below</span>
</p>
<p><span style="font-size:9px;color:blue;">#if</span><span style="font-size:9px;"> TESTCODE (if the TESTCODE symbol is defined using the <span style="color:blue;">#define</span> then true, false otherwise)</span></p>
<p><span style="font-size:9px;">// Test Code goes here&#8230;..</span><br /><span style="font-size:9px;color:blue;">#endif</span>
</p>
<p><span style="font-size:9px;">Also this is a very good way to handle multiple environments like in one project we had three environments like DEVELOPER, STAGE, PRODUCTION and we also had different databases. Now it may happen that we do not want the test data in our production database so that we can define these three symbols and then in the function returning the connection string we can conditionally return the appropriate connection string as below</span></p>
<p>
<p><span style="font-size:10px;color:blue;">internal string</span><span style="font-size:10px;"> GetConnectionString() { </span></p>
<p><span style="font-size:10px;">string conStr = <span style="color:rgb(163,21,21);">&#8220;&#8221;</span>;</span></p>
<p><span style="font-size:10px;color:blue;">#if</span><span style="font-size:10px;"> DEVELOPEMENT</span><br /><span style="font-size:10px;color:gray;">conStr = &#8220;development database connection string&#8221;;</span><br /><span style="font-size:10px;color:blue;">#endif</span><br /><span style="font-size:10px;color:blue;">#if</span><span style="font-size:10px;"> STAGE</span><br /><span style="font-size:10px;color:gray;">conStr = &#8220;Stage database connection string&#8221;;</span><br /><span style="font-size:10px;color:blue;">#endif</span><br /><span style="font-size:10px;color:blue;">#if</span><span style="font-size:10px;"> PRODUCTION</span><br /><span style="font-size:10px;color:gray;">conStr = &#8220;Production database connection string&#8221;;</span><br /><span style="font-size:10px;color:blue;">#endif</span><br /><span style="font-size:10px;">return conStr;</span><br /><span style="font-size:10px;">}</span>
</p>
<p><strong><span style="font-size:10px;">HOW TO DEFINE: </span></strong></p>
<p><span style="font-size:9px;">So now only if you have the above line (#define TESTCODE) in your file the above conditional code will compile, not otherwise. So in case you do not want the test code to be moved to the production environment dll then just go to the file and remove the #define TESTCODE.</span><br /><span style="font-size:9px;">These conditional compilation symbols can be defined at file level or the project level. To define it at file level we can put the #define SYMBOLNAME in the file itself. To define the project level symbol follow the below steps.</span><br /><span style="font-size:9px;">Right click the .csproj (project file) -&gt; click Properties -&gt; go to Build tab -&gt; find the Conditional compilation symbol and write the symbols in the text boxes. Multiple symbols can be separated by comma.</span><br /><span style="font-size:9px;">Now in ASP.NET 2.0 website this can be in the web.config file too as below</span><br /><span style="font-size:9px;color:blue;">&lt;</span><span style="font-size:9px;color:brown;">system.codedom</span><span style="font-size:9px;color:blue;">&gt;<br />&lt;</span><span style="font-size:9px;color:brown;">compilers</span><span style="font-size:9px;color:blue;">&gt;<br />&lt;</span><span style="font-size:9px;color:brown;">compiler </span><span style="font-size:9px;color:red;">language</span><span style="font-size:9px;color:blue;">=&#8221;c#;cs;csharp&#8221; extension=&#8221;.cs&#8221;<br /></span><span style="font-size:9px;color:red;">type</span><span style="font-size:9px;color:blue;">=&#8221;Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0,<br />Culture=neutral, PublicKeyToken=b77a5c561934e089&#8243;<br /></span><span style="font-size:9px;color:red;">compilerOptions</span><span style="font-size:9px;color:blue;">=&#8221;/d:SYMBOL1,SYMBOL2&#8243;/&gt;<br />&lt;</span><span style="font-size:9px;color:brown;">/compilers</span><span style="font-size:9px;color:blue;">&gt;<br />&lt;</span><span style="font-size:9px;color:brown;">/system.codedom</span><span style="font-size:9px;color:blue;">&gt;</span></p>
<p><strong><span style="font-size:10px;">USE <span style="color:blue;">#warning</span> AND <span style="color:blue;">#error</span> IN CODE REVIEW:</span></strong>
</p>
<p><span style="font-size:10px;">Two other important directives are <span style="color:blue;">#warning</span> and <span style="color:blue;">#error. </span>Let us see how can we use them. These directives can be used while reviewing the code. As when some senior programming guy reviewing the code and if he find some better alternative for a piece of code he/she can put a warning there like </span></p>
<p><span style="font-size:10px;color:blue;">#warning</span><span style="font-size:10px;"> Method implemented incorrectly. Do not use static variables.</span></p>
<p><span style="font-size:10px;">So whenever the code is compiled, we will find the above warning in the output window and the Error list window. If we find some bad code that is written wrongly then we can put #error MESSAGE so that the code will not be compiled ant the message will be shown in the output and the Error list window</span></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/pareshjagatia.wordpress.com/5/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/pareshjagatia.wordpress.com/5/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pareshjagatia.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pareshjagatia.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pareshjagatia.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pareshjagatia.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pareshjagatia.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pareshjagatia.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pareshjagatia.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pareshjagatia.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pareshjagatia.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pareshjagatia.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pareshjagatia.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pareshjagatia.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pareshjagatia.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pareshjagatia.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pareshjagatia.wordpress.com&amp;blog=3629307&amp;post=5&amp;subd=pareshjagatia&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pareshjagatia.wordpress.com/2008/04/30/c-pre-processor-directives-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/a064eb30504534be34d39fe0d74ac1ac?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pareshjagatia</media:title>
		</media:content>
	</item>
	</channel>
</rss>
