<?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>IBlog &#187; ASP.NET</title>
	<atom:link href="http://blog.objectpattern.com/category/asp-net/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.objectpattern.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Mon, 31 Oct 2011 15:03:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>HTTP 404 while asp.net web forms and spring.net project</title>
		<link>http://blog.objectpattern.com/asp-net/http-404-while-asp-net-web-forms-and-spring-net-project/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=http-404-while-asp-net-web-forms-and-spring-net-project</link>
		<comments>http://blog.objectpattern.com/asp-net/http-404-while-asp-net-web-forms-and-spring-net-project/#comments</comments>
		<pubDate>Fri, 01 Jul 2011 10:02:22 +0000</pubDate>
		<dc:creator>Himanshu</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Spring.NET]]></category>

		<guid isPermaLink="false">http://blog.objectpattern.com/asp-net/http-404-while-asp-net-web-forms-and-spring-net-project/</guid>
		<description><![CDATA[While doing some refactoring with the project, I suddenly start getting HTTP 404, and that to for all pages that exists and was working few minutes back. I was amused to get the error, with the fact that pages existed, I could see them and feel them! After a while, I noticed that I have [...]]]></description>
			<content:encoded><![CDATA[<p>While doing some refactoring with the project, I suddenly start getting HTTP 404, and that to for all pages that exists and was working few minutes back. I was amused to get the error, with the fact that pages existed, I could see them and feel them! After a while, I noticed that I have deleted a existing .aspx file from project which I forgot to remove from spring.net configuration file.</p>
<p>If you add any .aspx in Spring.Net config that do not exists, Spring.NET brings you to yellow screen with appropriate message. But not when you delete one from project and forget to remove from config file! At least not all the time.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectpattern.com/asp-net/http-404-while-asp-net-web-forms-and-spring-net-project/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ASP.NET Postback on table row click</title>
		<link>http://blog.objectpattern.com/dot-net/asp-net-postback-on-table-row-click/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=asp-net-postback-on-table-row-click</link>
		<comments>http://blog.objectpattern.com/dot-net/asp-net-postback-on-table-row-click/#comments</comments>
		<pubDate>Wed, 05 Jan 2011 03:04:37 +0000</pubDate>
		<dc:creator>Himanshu</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://blog.objectpattern.com/dot-net/asp-net-postback-on-table-row-click/</guid>
		<description><![CDATA[When you need to go back to the server for further processing on clicking of a html element, for example on html table row click, below code may help you provide such functioning in ASP.NET.
Well, actually to allow control to support bubbling of the events, and allow user of the control to specify CommandName and [...]]]></description>
			<content:encoded><![CDATA[<p>When you need to go back to the server for further processing on clicking of a html element, for example on html table row click, below code may help you provide such functioning in ASP.NET.</p>
<p>Well, actually to allow control to support bubbling of the events, and allow user of the control to specify CommandName and CommandArgument while being used in template controls,  there is some extract effort, essentially will need to implement IButtonControl. Let’s see the code below that I have implemented to provide function of  selecting row when clicked on it.</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>[ToolboxData(<span class="str">"&lt;{0}:ListViewRowClickCommand  CommandName=\"Select\" runat=\"server\"&gt;&lt;/{0}:ListViewRowClickCommand&gt;"</span>)]</pre>
<pre><span class="lnum">   2:  </span><span class="kwrd">public</span> <span class="kwrd">class</span> ListViewRowClickCommand : HtmlTableRow, IButtonControl, IPostBackEventHandler</pre>
<pre class="alt"><span class="lnum">   3:  </span>{</pre>
<pre><span class="lnum">   4:  </span>    <span class="kwrd">public</span> <span class="kwrd">bool</span> DisableCommand { get; set; }</pre>
<pre class="alt"><span class="lnum">   5:  </span>    <span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> Render(HtmlTextWriter writer)</pre>
<pre><span class="lnum">   6:  </span>    {</pre>
<pre class="alt"><span class="lnum">   7:  </span>        writer.WriteBeginTag(<span class="str">"tr"</span>);</pre>
<pre><span class="lnum">   8:  </span>        <span class="kwrd">if</span> (ID != <span class="kwrd">null</span>)</pre>
<pre class="alt"><span class="lnum">   9:  </span>            writer.WriteAttribute(<span class="str">"id"</span>, ClientID);</pre>
<pre><span class="lnum">  10:  </span>        <span class="kwrd">if</span> (!DesignMode)</pre>
<pre class="alt"><span class="lnum">  11:  </span>        {</pre>
<pre><span class="lnum">  12:  </span>            <span class="kwrd">if</span> (!DisableCommand)</pre>
<pre class="alt"><span class="lnum">  13:  </span>                writer.WriteAttribute(<span class="str">"onclick"</span>, <span class="str">"javascript:"</span> +</pre>
<pre><span class="lnum">  14:  </span>                    Page.ClientScript.GetPostBackEventReference(<span class="kwrd">this</span>, CommandArgument));</pre>
<pre class="alt"><span class="lnum">  15:  </span>        }</pre>
<pre><span class="lnum">  16:  </span>        Attributes.Render(writer);</pre>
<pre class="alt"><span class="lnum">  17:  </span>        writer.Write(HtmlTextWriter.TagRightChar);</pre>
<pre><span class="lnum">  18:  </span></pre>
<pre class="alt"><span class="lnum">  19:  </span>        RenderChildren(writer);</pre>
<pre><span class="lnum">  20:  </span>        writer.WriteEndTag(<span class="str">"tr"</span>);</pre>
<pre class="alt"><span class="lnum">  21:  </span>    }</pre>
<pre><span class="lnum">  22:  </span></pre>
<pre class="alt"><span class="lnum">  23:  </span>    <span class="kwrd">public</span> <span class="kwrd">bool</span> CausesValidation</pre>
<pre><span class="lnum">  24:  </span>    {</pre>
<pre class="alt"><span class="lnum">  25:  </span>        get { <span class="kwrd">return</span> (<span class="kwrd">bool</span>)(ViewState[<span class="str">"CausesValidation"</span>] ?? <span class="kwrd">true</span>); }</pre>
<pre><span class="lnum">  26:  </span>        set { ViewState[<span class="str">"CausesValidation"</span>] = <span class="kwrd">value</span>; }</pre>
<pre class="alt"><span class="lnum">  27:  </span>    }</pre>
<pre><span class="lnum">  28:  </span></pre>
<pre class="alt"><span class="lnum">  29:  </span>    <span class="kwrd">public</span> <span class="kwrd">string</span> CommandArgument</pre>
<pre><span class="lnum">  30:  </span>    {</pre>
<pre class="alt"><span class="lnum">  31:  </span>        get { <span class="kwrd">return</span> (<span class="kwrd">string</span>)ViewState[<span class="str">"CommandArgument"</span>]; }</pre>
<pre><span class="lnum">  32:  </span>        set { ViewState[<span class="str">"CommandArgument"</span>] = <span class="kwrd">value</span>; }</pre>
<pre class="alt"><span class="lnum">  33:  </span>    }</pre>
<pre><span class="lnum">  34:  </span></pre>
<pre class="alt"><span class="lnum">  35:  </span>    <span class="kwrd">public</span> <span class="kwrd">string</span> CommandName</pre>
<pre><span class="lnum">  36:  </span>    {</pre>
<pre class="alt"><span class="lnum">  37:  </span>        get { <span class="kwrd">return</span> (<span class="kwrd">string</span>)ViewState[<span class="str">"CommandName"</span>]; }</pre>
<pre><span class="lnum">  38:  </span>        set { ViewState[<span class="str">"CommandName"</span>] = <span class="kwrd">value</span>; }</pre>
<pre class="alt"><span class="lnum">  39:  </span>    }</pre>
<pre><span class="lnum">  40:  </span></pre>
<pre class="alt"><span class="lnum">  41:  </span>    <span class="kwrd">public</span> <span class="kwrd">string</span> PostBackUrl</pre>
<pre><span class="lnum">  42:  </span>    {</pre>
<pre class="alt"><span class="lnum">  43:  </span>        get { <span class="kwrd">return</span> (<span class="kwrd">string</span>)ViewState[<span class="str">"PostBackUrl"</span>]; }</pre>
<pre><span class="lnum">  44:  </span>        set { ViewState[<span class="str">"PostBackUrl"</span>] = <span class="kwrd">value</span>; }</pre>
<pre class="alt"><span class="lnum">  45:  </span>    }</pre>
<pre><span class="lnum">  46:  </span></pre>
<pre class="alt"><span class="lnum">  47:  </span>    <span class="kwrd">public</span> <span class="kwrd">string</span> ValidationGroup</pre>
<pre><span class="lnum">  48:  </span>    {</pre>
<pre class="alt"><span class="lnum">  49:  </span>        get { <span class="kwrd">return</span> (<span class="kwrd">string</span>)ViewState[<span class="str">"ValidationGroup"</span>]; }</pre>
<pre><span class="lnum">  50:  </span>        set { ViewState[<span class="str">"ValidationGroup"</span>] = <span class="kwrd">value</span>; }</pre>
<pre class="alt"><span class="lnum">  51:  </span>    }</pre>
<pre><span class="lnum">  52:  </span></pre>
<pre class="alt"><span class="lnum">  53:  </span>    <span class="kwrd">public</span> <span class="kwrd">event</span> EventHandler Click;</pre>
<pre><span class="lnum">  54:  </span>    <span class="kwrd">public</span> <span class="kwrd">event</span> CommandEventHandler Command;</pre>
<pre class="alt"><span class="lnum">  55:  </span></pre>
<pre><span class="lnum">  56:  </span>    <span class="kwrd">public</span> <span class="kwrd">void</span> RaisePostBackEvent(<span class="kwrd">string</span> eventArgument)</pre>
<pre class="alt"><span class="lnum">  57:  </span>    {</pre>
<pre><span class="lnum">  58:  </span>        <span class="kwrd">if</span> (CausesValidation)</pre>
<pre class="alt"><span class="lnum">  59:  </span>        {</pre>
<pre><span class="lnum">  60:  </span>            <span class="kwrd">if</span> (Page.IsPostBack)</pre>
<pre class="alt"><span class="lnum">  61:  </span>                Page.Validate();</pre>
<pre><span class="lnum">  62:  </span>            <span class="kwrd">if</span> (!Page.IsValid)</pre>
<pre class="alt"><span class="lnum">  63:  </span>                <span class="kwrd">return</span>;</pre>
<pre><span class="lnum">  64:  </span>        }</pre>
<pre class="alt"><span class="lnum">  65:  </span></pre>
<pre><span class="lnum">  66:  </span>        OnClick(EventArgs.Empty);</pre>
<pre class="alt"><span class="lnum">  67:  </span>        OnCommand(<span class="kwrd">new</span> CommandEventArgs(CommandName, CommandArgument));</pre>
<pre><span class="lnum">  68:  </span>    }</pre>
<pre class="alt"><span class="lnum">  69:  </span></pre>
<pre><span class="lnum">  70:  </span>    <span class="kwrd">protected</span> <span class="kwrd">virtual</span> <span class="kwrd">void</span> OnCommand(CommandEventArgs eventArgs)</pre>
<pre class="alt"><span class="lnum">  71:  </span>    {</pre>
<pre><span class="lnum">  72:  </span>        <span class="kwrd">if</span> (Command != <span class="kwrd">null</span>)</pre>
<pre class="alt"><span class="lnum">  73:  </span>            Command(<span class="kwrd">this</span>, eventArgs);</pre>
<pre><span class="lnum">  74:  </span></pre>
<pre class="alt"><span class="lnum">  75:  </span>        RaiseBubbleEvent(<span class="kwrd">this</span>, eventArgs);</pre>
<pre><span class="lnum">  76:  </span>    }</pre>
<pre class="alt"><span class="lnum">  77:  </span></pre>
<pre><span class="lnum">  78:  </span>    <span class="kwrd">protected</span> <span class="kwrd">virtual</span> <span class="kwrd">void</span> OnClick(EventArgs eventArgs)</pre>
<pre class="alt"><span class="lnum">  79:  </span>    {</pre>
<pre><span class="lnum">  80:  </span>        <span class="kwrd">if</span> (Click != <span class="kwrd">null</span>)</pre>
<pre class="alt"><span class="lnum">  81:  </span>            Click(<span class="kwrd">this</span>, eventArgs);</pre>
<pre><span class="lnum">  82:  </span>    }</pre>
<pre class="alt"><span class="lnum">  83:  </span>}</pre>
</div>
<p><!--</p>
<p>.csharpcode, .csharpcode pre<br />
{<br />
font-size: small;<br />
color: black;<br />
font-family: consolas, "Courier New", courier, monospace;<br />
background-color: #ffffff;<br />
/*white-space: pre;*/<br />
}<br />
.csharpcode pre { margin: 0em; }<br />
.csharpcode .rem { color: #008000; }<br />
.csharpcode .kwrd { color: #0000ff; }<br />
.csharpcode .str { color: #006080; }<br />
.csharpcode .op { color: #0000c0; }<br />
.csharpcode .preproc { color: #cc6633; }<br />
.csharpcode .asp { background-color: #ffff00; }<br />
.csharpcode .html { color: #800000; }<br />
.csharpcode .attr { color: #ff0000; }<br />
.csharpcode .alt<br />
{<br />
background-color: #f4f4f4;<br />
width: 100%;<br />
margin: 0em;<br />
}<br />
.csharpcode .lnum { color: #606060; } --><!--</p>
<p>.csharpcode, .csharpcode pre<br />
{<br />
font-size: small;<br />
color: black;<br />
font-family: consolas, "Courier New", courier, monospace;<br />
background-color: #ffffff;<br />
/*white-space: pre;*/<br />
}<br />
.csharpcode pre { margin: 0em; }<br />
.csharpcode .rem { color: #008000; }<br />
.csharpcode .kwrd { color: #0000ff; }<br />
.csharpcode .str { color: #006080; }<br />
.csharpcode .op { color: #0000c0; }<br />
.csharpcode .preproc { color: #cc6633; }<br />
.csharpcode .asp { background-color: #ffff00; }<br />
.csharpcode .html { color: #800000; }<br />
.csharpcode .attr { color: #ff0000; }<br />
.csharpcode .alt<br />
{<br />
background-color: #f4f4f4;<br />
width: 100%;<br />
margin: 0em;<br />
}<br />
.csharpcode .lnum { color: #606060; } --></p>
<p>Above control can be used as below:</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>...</pre>
<pre><span class="lnum">   2:  </span></pre>
<pre class="alt"><span class="lnum">   3:  </span>&lt;asp:ListView ID=<span class="str">"listViewOfSomething"</span> runat=<span class="str">"server"</span> OnSelectedIndexChanging=<span class="str">"OnSelectedIndexChanging"</span>&gt;</pre>
<pre><span class="lnum">   4:  </span>    &lt;LayoutTemplate&gt;</pre>
<pre class="alt"><span class="lnum">   5:  </span>        &lt;table <span class="kwrd">id</span>=<span class="str">"htmlTableOfSomething"</span> &gt;</pre>
<pre><span class="lnum">   6:  </span>            &lt;tbody&gt;</pre>
<pre class="alt"><span class="lnum">   7:  </span>                &lt;asp:PlaceHolder ID=<span class="str">"itemPlaceholder"</span> runat=<span class="str">"server"</span> /&gt;</pre>
<pre><span class="lnum">   8:  </span>            &lt;/tbody&gt;</pre>
<pre class="alt"><span class="lnum">   9:  </span>        &lt;/table&gt;</pre>
<pre><span class="lnum">  10:  </span>    &lt;/LayoutTemplate&gt;</pre>
<pre class="alt"><span class="lnum">  11:  </span>    &lt;ItemTemplate&gt;</pre>
<pre><span class="lnum">  12:  </span>        &lt;vdd:ListViewRowClickCommand ID=<span class="str">"ListViewRowClickCommand"</span> runat=<span class="str">"server"</span></pre>
<pre class="alt"><span class="lnum">  13:  </span>            CommandName=<span class="str">"Select"</span> Class=<span class="str">"SomeCssClassForRow"</span> &gt;</pre>
<pre><span class="lnum">  14:  </span>            &lt;td <span class="kwrd">class</span>=<span class="str">"CssClassForColumn"</span>&gt;</pre>
<pre class="alt"><span class="lnum">  15:  </span></pre>
<pre><span class="lnum">  16:  </span>...</pre>
</div>
<p>Feel free to put comments in case if things are not clear.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectpattern.com/dot-net/asp-net-postback-on-table-row-click/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sending email message having embedded image (.NET)</title>
		<link>http://blog.objectpattern.com/dot-net/sending-email-message-having-embedded-image-net/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=sending-email-message-having-embedded-image-net</link>
		<comments>http://blog.objectpattern.com/dot-net/sending-email-message-having-embedded-image-net/#comments</comments>
		<pubDate>Fri, 15 May 2009 05:16:25 +0000</pubDate>
		<dc:creator>Himanshu</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">/post/Sending-email-message-having-embedded-image-(NET).aspx</guid>
		<description><![CDATA[Does your .net application send email messages? Does it send formatted email messages? I think applications should always send formatted email messages instead of text only. (Are asking why? Simple, formatted messages are much more capable, presentable, &#8230;).
Counter argument: Some user uses email client that are not capable to show HTML messages. Or someone is [...]]]></description>
			<content:encoded><![CDATA[<p>Does your .net application send email messages? Does it send formatted email messages? I think applications should always send formatted email messages instead of text only. (Are asking why? Simple, formatted messages are much more capable, presentable, &#8230;).</p>
<p>Counter argument: Some user uses email client that are not capable to show HTML messages. Or someone is doing it for security purpose. Okay, I agree, then send both the views; text view as well as HTML view. Using .NET, one can send multi view email messages, depending on email client settings and/or capability, client is expected to pick the right view and shows that to the user.</p>
<p>Next question is, say we have decided to send email in html and text view, can we send images and style sheets embedded with email? Answers is yes. Here is how one can send multi-part email message using .net libraries that has embedded image.</p>
<p>Here goes the first step, create MailMessage object and setup that with appropriate values</p>
<div style="line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.3%; font-family: consolas, 'Courier New', courier, monospace; height: 60px; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;">
<div style="line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   1:</span> var from = <span style="color: #0000ff">new</span> MailAddress(<span style="color: #006080">"admin@objectpattern.com"</span>, <span style="color: #006080">"Himanshu"</span>);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   2:</span> var to = <span style="color: #0000ff">new</span> MailAddress(<span style="color: #006080">"himanshu@objectpattern.net"</span>);</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   3:</span> var message = <span style="color: #0000ff">new</span> MailMessage(from, to) { Subject = <span style="color: #006080">"Hi from ObjectPattern"</span>};</pre>
</div>
</div>
<p>next step changes. As we want to have two views &#8211; text and html, we will have to create email body differently.</p>
<p>in these lines of code, there are certain important points</p>
<div style="line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.59%; font-family: consolas, 'Courier New', courier, monospace; height: 281px; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;">
<div style="line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   1:</span> <span style="color: #008000">//creating text view</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   2:</span> var textViewContent = <span style="color: #006080">"Test content for text view"</span>;</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   3:</span> var textView = AlternateView.CreateAlternateViewFromString(textViewContent, Encoding.UTF8,</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   4:</span>                                                            MediaTypeNames.Text.Plain);</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   5:</span> <span style="color: #008000">//creating html view </span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   6:</span> var htmlViewContent = <span style="color: #006080">"

Html content containing image logo

Thanks,
ObjectPattern
<img src="cid:logo.png" alt="logo" />"</span>;</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   7:</span> var htmlView = AlternateView.CreateAlternateViewFromString(htmlViewContent, Encoding.UTF8,</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   8:</span>                                                            MediaTypeNames.Text.Html);</pre>
</div>
</div>
<p>that I would like to bring in to your notice.</p>
<ul>
<li>Notice that we are not assigning Body property of MailMessage type</li>
<li>While creating view, we are specifying media type name as either plain text or html text, it can also be rich text.</li>
<li>We have created an img tag that referring to source as &#8216;cid:logo.png&#8217;</li>
</ul>
<p>okay now how we will embed image into email message? That&#8217;s easy as well:</p>
<div style="line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.66%; font-family: consolas, 'Courier New', courier, monospace; height: 76px; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;">
<div style="line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   1:</span> var logo = <span style="color: #0000ff">new</span> LinkedResource(<span style="color: #006080">"images/logo.png"</span>, MediaTypeNames.Image.Jpeg) {ContentId = <span style="color: #006080">"logo.png"</span>};</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   2:</span> htmlView.LinkedResources.Add(logo);</pre>
</div>
</div>
<p>here in first line, first parameter of constructor (&#8220;image/logo.png&#8221; text) specifies the path of the image file. One can also supply image content as stream if its not coming directly from the file. Now remember, in above section, we had specified the src attribute of img tag, that should match with content id. Else image will not be shown correctly in email client. Also notice that we are adding this image to html view.</p>
<p>We are almost done now. All we need to do now is to add views to message object and sending using SMTP client.</p>
<div style="line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 99.11%; font-family: consolas, 'Courier New', courier, monospace; height: 58px; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;">
<div style="line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   1:</span> message.AlternateViews.Add(textView);</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   2:</span> message.AlternateViews.Add(htmlView);</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #606060">   3:</span></pre>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectpattern.com/dot-net/sending-email-message-having-embedded-image-net/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Paging of SQL Server records</title>
		<link>http://blog.objectpattern.com/dot-net/paging-of-sql-server-records/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=paging-of-sql-server-records</link>
		<comments>http://blog.objectpattern.com/dot-net/paging-of-sql-server-records/#comments</comments>
		<pubDate>Tue, 05 Aug 2008 06:29:41 +0000</pubDate>
		<dc:creator>Himanshu</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Sql Server 2005]]></category>

		<guid isPermaLink="false">/post/Paging-of-SQL-Server-records.aspx</guid>
		<description><![CDATA[In one of my ASP.NET, SQL Server project, we were expected to provide paging in the ASP.NET GridView. Microsoft&#8217;s very common sample will do this using Dataset filled with all records. If someone is doing GridView paging, s/he is doing it not waste server&#8217;s or client&#8217;s precious resources, Isn&#8217;t it?
To me, it make more sense [...]]]></description>
			<content:encoded><![CDATA[<p>In one of my ASP.NET, SQL Server project, we were expected to provide paging in the ASP.NET GridView. Microsoft&#8217;s very common sample will do this using Dataset filled with all records. If someone is doing GridView paging, s/he is doing it not waste server&#8217;s or client&#8217;s precious resources, Isn&#8217;t it?</p>
<p>To me, it make more sense to do paging of records being fetched in server memory along with view paging. What if table in question has more then 100,000 (1 lack) records?</p>
<p>Digging a bit further, I found a resource which explains how to do paging of records being sent from stored procedure. But it was expecting to have auto identity as primary key in the table. And we were so fortunate that we couldn&#8217;t have db design such that we can afford to have auto identity primary key, and so that solution to the paging problem. On doing some more finding, we all agreed to a solution that is described below. It&#8217;s not fully optimized, as it do not have any optimization for SQL Server to prepare result sets. But worked for our need in specific project as even in 100,000 records it was working very fast.</p>
<p>In our solution, stored procedure that will fetch records from table and return to caller will needs to have two addition parameters, @RowIndexFrom and @RowIndexTo</p>
<p>Getting customers by page will look like following,</p>
<div style="line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: consolas, 'Courier New', courier, monospace; height: 242px; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: gray 1px solid; padding: 4px;">
<div style="line-height: 12pt; background-color: #f4f4f4; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff">CREATE</span> <span style="color: #0000ff">PROCEDURE</span> [dbo].[GetCustomersPage]</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">(</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    @RowIndexFrom <span style="color: #0000ff">int</span>,</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    @RowIndexTo <span style="color: #0000ff">int</span></pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">)</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff">AS</span></pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff">BEGIN</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff">SET</span> NOCOUNT <span style="color: #0000ff">ON</span>;</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff">WITH</span> IndexedCustomers <span style="color: #0000ff">AS</span></pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    (</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color: #0000ff">SELECT</span></pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            ROW_NUMBER() <span style="color: #0000ff">OVER</span> (<span style="color: #0000ff">ORDER</span> <span style="color: #0000ff">BY</span> Id) <span style="color: #0000ff">AS</span> rowIndex,</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            Customers.*</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        <span style="color: #0000ff">FROM</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">            Customers</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    )</pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff">SELECT</span> * <span style="color: #0000ff">FROM</span> IndexedCustomers <span style="color: #0000ff">WHERE</span> rowIndex <span style="color: #0000ff">BETWEEN</span> @RowIndexFrom <span style="color: #0000ff">AND</span> @RowIndexTo</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"> </pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff">SELECT</span> <span style="color: #0000ff">COUNT</span>(*)</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff">FROM</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        Customers</pre>
<pre style="line-height: 12pt; background-color: white; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff">END</span></pre>
<pre style="line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: consolas, 'Courier New', courier, monospace; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff">GO</span></pre>
</div>
</div>
<p> </p>
<p>The stored procedure returns two result set, first will be records for given page (defined by different between @RowIndexFrom and @RowIndexTo parameters). And the second result set will give total number of records for give query. Second result set will help preparing pages list. So, if first page needs to be retrieved of page size 10, parameter values should be 1 and 10 respectively.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.objectpattern.com/dot-net/paging-of-sql-server-records/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

