<?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>debug mode...... &#187; CSharp</title>
	<atom:link href="http://debugmode.net/category/csharp/feed/" rel="self" type="application/rss+xml" />
	<link>http://debugmode.net</link>
	<description>debugging the learning </description>
	<lastBuildDate>Tue, 21 May 2013 03:53:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='debugmode.net' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/a4ee6598425293dab3d0c39b7600711a?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>debug mode...... &#187; CSharp</title>
		<link>http://debugmode.net</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://debugmode.net/osd.xml" title="debug mode......" />
	<atom:link rel='hub' href='http://debugmode.net/?pushpress=hub'/>
		<item>
		<title>Evolution of C Sharp Language: Picture Blog</title>
		<link>http://debugmode.net/2012/11/27/evolution-of-c-sharp-language-picture-blog/</link>
		<comments>http://debugmode.net/2012/11/27/evolution-of-c-sharp-language-picture-blog/#comments</comments>
		<pubDate>Tue, 27 Nov 2012 12:22:56 +0000</pubDate>
		<dc:creator>Dhananjay Kumar</dc:creator>
				<category><![CDATA[CSharp]]></category>
		<category><![CDATA[CSharp Vesrions]]></category>
		<category><![CDATA[Interview]]></category>

		<guid isPermaLink="false">http://dhananjay25.wordpress.com/?p=11949</guid>
		<description><![CDATA[I was working on something and suddenly a mail popped up. I did not know the sender but I found he/she was a job aspirant. I found him/her very impatient and gist of his/her mail was, &#8220;Sir tomorrow I got<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://debugmode.net/2012/11/27/evolution-of-c-sharp-language-picture-blog/">Read more &#8250;</a></div><!-- end of .read-more --><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=debugmode.net&#038;blog=10538757&#038;post=11949&#038;subd=dhananjay25&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><span style="font-size:12pt;">I was working on something and suddenly a mail popped up. I did not know the sender but I found he/she was a job aspirant. I found him/her very impatient and gist of his/her mail was, &#8220;Sir tomorrow I got a job interview. Could you please help me with different versions of C Sharp with specific features in each versions? I just want to know the features name &#8220;<br /></span></p>
<p><span style="font-size:12pt;">I found this question very interesting. Since majority of the time we focus on implementation of a feature. We discuss how a particular feature can be implemented in greater extent but we tend to forget in which version of C Sharp that particular feature got introduced. For a junior level programmer interview, this could be a vital question that list different features of C Sharp version wise. I am trying to answer this question pictorially below,<br /></span></p>
<p><a href="http://dhananjay25.files.wordpress.com/2012/11/image65.png"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="image" border="0" alt="image" src="http://dhananjay25.files.wordpress.com/2012/11/image_thumb65.png?w=617&#038;h=480" width="617" height="480"/></a> </p>
<p><span style="font-size:12pt;"></span></p>
<p><span style="font-size:12pt;">I am sure taking a high level look on this picture before going to interview could be a help. I hope you find this picture post useful. Thanks for reading. </span></p>
<br />Filed under: <a href='http://debugmode.net/category/csharp/'>CSharp</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dhananjay25.wordpress.com/11949/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dhananjay25.wordpress.com/11949/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dhananjay25.wordpress.com/11949/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dhananjay25.wordpress.com/11949/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dhananjay25.wordpress.com/11949/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dhananjay25.wordpress.com/11949/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dhananjay25.wordpress.com/11949/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dhananjay25.wordpress.com/11949/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dhananjay25.wordpress.com/11949/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dhananjay25.wordpress.com/11949/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dhananjay25.wordpress.com/11949/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dhananjay25.wordpress.com/11949/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=debugmode.net&#038;blog=10538757&#038;post=11949&#038;subd=dhananjay25&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://debugmode.net/2012/11/27/evolution-of-c-sharp-language-picture-blog/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c90eb841e3efad072a72427a27409cd1?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">dhananjay25</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2012/11/image_thumb65.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Method Caller Information in C Sharp 5.0</title>
		<link>http://debugmode.net/2012/11/27/method-caller-information-in-c-sharp-5-0/</link>
		<comments>http://debugmode.net/2012/11/27/method-caller-information-in-c-sharp-5-0/#comments</comments>
		<pubDate>Tue, 27 Nov 2012 10:15:50 +0000</pubDate>
		<dc:creator>Dhananjay Kumar</dc:creator>
				<category><![CDATA[CSharp]]></category>
		<category><![CDATA[CSharp 5]]></category>
		<category><![CDATA[Method Caller Information]]></category>
		<category><![CDATA[Optional argument]]></category>

		<guid isPermaLink="false">http://dhananjay25.wordpress.com/?p=11931</guid>
		<description><![CDATA[Before we understand Method Caller Information feature of C# 5.0, we need to understand Optional Parameter feature of C# 4.0. C Sharp 4.0 introduced Optional Parameter feature . According to this feature, in function call only required parameters are needed<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://debugmode.net/2012/11/27/method-caller-information-in-c-sharp-5-0/">Read more &#8250;</a></div><!-- end of .read-more --><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=debugmode.net&#038;blog=10538757&#038;post=11931&#038;subd=dhananjay25&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><span style="font-size:12pt;">Before we understand Method Caller Information feature of C# 5.0, we need to understand Optional Parameter feature of C# 4.0.<br />
</span></p>
<p><a href="http://debugmode.net/2009/11/26/optional-argument-in-c-4-0/"><span style="font-size:12pt;">C Sharp 4.0 introduced Optional Parameter feature</span></a><span style="font-size:12pt;"> . According to this feature, in function call only required parameters are needed to be passed. If value of Optional Parameters are not provided then they will take default constant value. To understand it better, let us take following function as example. </span></p>
<pre class="brush: csharp; title: ; notranslate">

static void Display(string Name, int age,string Nationality=&quot;Indian&quot;)
{

Console.WriteLine(&quot;Hey &quot; + Name + &quot; you are &quot; + age + &quot; old &quot; + Nationality);
}

</pre>
<p><span style="font-size:12pt;">In function <strong>Display,</strong> Nationality is an optional parameter. So while calling this function you will get intellisense suggesting you that if not provided parameter Nationality will take constant string value &#8220;Indian&#8221;</span></p>
<p><a href="http://dhananjay25.files.wordpress.com/2012/11/image59.png"><img style="display:inline;border:0;" title="image" alt="image" src="http://dhananjay25.files.wordpress.com/2012/11/image_thumb59.png?w=499&#038;h=98" height="98" width="499" /></a> <span style="font-size:12pt;"><br />
</span></p>
<p><span style="font-size:12pt;">You can call Display function omitting value of parameter Nationality as following </span></p>
<pre class="brush: csharp; title: ; notranslate">
static void Main(string[] args)
{
Display(&quot;dj&quot;, 28);
Console.ReadKey(true);

}

</pre>
<p><span style="font-size:12pt;">In output you will notice that value of parameter Nationality is set to default string constant &#8220;Indian&#8221; </span></p>
<p><a href="http://dhananjay25.files.wordpress.com/2012/11/image60.png"><img style="display:inline;border:0;" title="image" alt="image" src="http://dhananjay25.files.wordpress.com/2012/11/image_thumb60.png?w=265&#038;h=79" height="79" width="265" /></a> <span style="font-size:12pt;"><br />
</span><span style="font-size:12pt;">Now you can see that Optional Parameters has taken the default constant value. C# 5.0 gives us liberty or allow us to attribute optional parameter with <strong>caller info attributes</strong>. By providing caller info attributes at the runtime optional parameter value will be replaced by dynamic values for caller info attributes. There are three caller info attributes are available, </span></p>
<p><a href="http://dhananjay25.files.wordpress.com/2012/11/image61.png"><img style="display:inline;border:0;" title="image" alt="image" src="http://dhananjay25.files.wordpress.com/2012/11/image_thumb61.png?w=721&#038;h=295" height="295" width="721" /></a> <span style="font-size:12pt;"><br />
</span></p>
<p><span style="font-size:12pt;">Let us go ahead and rewrite Display function with Method Caller Information attribute on optional parameters. </span></p>
<p><a href="http://dhananjay25.files.wordpress.com/2012/11/image62.png"><img style="display:inline;border:0;" title="image" alt="image" src="http://dhananjay25.files.wordpress.com/2012/11/image_thumb62.png?w=624&#038;h=195" height="195" width="624" /></a> <span style="font-size:12pt;"><br />
</span></p>
<p><span style="font-size:12pt;">You see in above function definition [see the rectangle], we have attributed three optional parameters with method caller information. We can display method caller information as following,<br />
</span></p>
<pre class="brush: csharp; title: ; notranslate">

static void Display(string Name,
int age,
string Nationality=&quot;Indian&quot;,
[CallerMemberName] string Caller = &quot;&quot;,
[CallerFilePath] string file=&quot;&quot;,
[CallerLineNumber] int line=0)
{

Console.WriteLine(&quot;Hey &quot; + Name + &quot; you are &quot; + age + &quot; old &quot; + Nationality);
Console.WriteLine(&quot;This function is called  from member &quot; + Caller + &quot; file &quot; + file + &quot; line &quot; + line);
}

</pre>
<p><span style="font-size:12pt;">Now when you call the function you will get method caller information printed. Expected output would be as following </span></p>
<p><a href="http://dhananjay25.files.wordpress.com/2012/11/image63.png"><img style="display:inline;border:0;" title="image" alt="image" src="http://dhananjay25.files.wordpress.com/2012/11/image_thumb63.png?w=624&#038;h=145" height="145" width="624" /></a> <span style="font-size:12pt;"><br />
</span><span style="font-size:12pt;">Method Caller Information is particularly very useful in logging of the application. For high level logging, I would consider using Method Caller Information attributes along with optional parameters. I hope you find this post on Method Caller Information in C# 5.0 useful. Thanks for reading.<br />
</span></p>
<br />Filed under: <a href='http://debugmode.net/category/csharp/'>CSharp</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dhananjay25.wordpress.com/11931/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dhananjay25.wordpress.com/11931/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dhananjay25.wordpress.com/11931/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dhananjay25.wordpress.com/11931/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dhananjay25.wordpress.com/11931/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dhananjay25.wordpress.com/11931/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dhananjay25.wordpress.com/11931/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dhananjay25.wordpress.com/11931/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dhananjay25.wordpress.com/11931/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dhananjay25.wordpress.com/11931/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dhananjay25.wordpress.com/11931/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dhananjay25.wordpress.com/11931/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=debugmode.net&#038;blog=10538757&#038;post=11931&#038;subd=dhananjay25&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://debugmode.net/2012/11/27/method-caller-information-in-c-sharp-5-0/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c90eb841e3efad072a72427a27409cd1?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">dhananjay25</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2012/11/image_thumb59.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2012/11/image_thumb60.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2012/11/image_thumb61.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2012/11/image_thumb62.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2012/11/image_thumb63.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>CSharp Interview Question: What is Action in CSharp</title>
		<link>http://debugmode.net/2012/02/20/csharp-interview-question-what-is-action-in-csharp/</link>
		<comments>http://debugmode.net/2012/02/20/csharp-interview-question-what-is-action-in-csharp/#comments</comments>
		<pubDate>Mon, 20 Feb 2012 18:20:13 +0000</pubDate>
		<dc:creator>Dhananjay Kumar</dc:creator>
				<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Action]]></category>
		<category><![CDATA[Interview Question]]></category>

		<guid isPermaLink="false">https://dhananjay25.wordpress.com/?p=9806</guid>
		<description><![CDATA[One of my friends called me after his interview as for a developer role in an esteemed organization. One of the question, interviewer asked him, After talking to him, I thought why not to blog about it? I am trying<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://debugmode.net/2012/02/20/csharp-interview-question-what-is-action-in-csharp/">Read more &#8250;</a></div><!-- end of .read-more --><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=debugmode.net&#038;blog=10538757&#038;post=9806&#038;subd=dhananjay25&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><font size="3">One of my friends called me after his interview as for a developer role in an esteemed organization. One of the question, interviewer asked him,</font></p>
<p><a href="http://dhananjay25.files.wordpress.com/2012/02/image54.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;margin:5px;" title="image" border="0" alt="image" src="http://dhananjay25.files.wordpress.com/2012/02/image_thumb54.png?w=385&#038;h=165" width="385" height="165" /></a></p>
<p><font size="3">After talking to him, I thought why not to blog about it? I am trying here to use minimum words and optimum code samples can be discussed with interviewer as answer of this question</font>. </p>
<p><font size="4"><b>Action</b> is type of delegate</font> </p>
<ol>
<li><font size="3">It returns no value. </font></li>
<li><font size="3">It may take 0 parameter to 16 parameters.</font> </li>
</ol>
<p><font size="3">For example below Action can encapsulates a method taking two integer input parameter and returning void.</font> </p>
<p>&#160;</p>
<p><a href="http://dhananjay25.files.wordpress.com/2012/02/image55.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://dhananjay25.files.wordpress.com/2012/02/image_thumb55.png?w=446&#038;h=52" width="446" height="52" /></a></p>
<p><font size="3">So if you have method like below,</font> </p>
<p><a href="http://dhananjay25.files.wordpress.com/2012/02/clip_image0021.jpg"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="clip_image002" border="0" alt="clip_image002" src="http://dhananjay25.files.wordpress.com/2012/02/clip_image002_thumb1.jpg?w=397&#038;h=116" width="397" height="116" /></a></p>
<p><font size="3">You can encapsulate method <b>Display</b> in Action <b>MyDelegate</b> as below,</font> </p>
<p><a href="http://dhananjay25.files.wordpress.com/2012/02/image56.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://dhananjay25.files.wordpress.com/2012/02/image_thumb56.png?w=343&#038;h=42" width="343" height="42" /></a></p>
<p><font size="3">An Action with one input parameter is defined in <b>System</b> namespace as below,</font> </p>
<p><a href="http://dhananjay25.files.wordpress.com/2012/02/image57.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://dhananjay25.files.wordpress.com/2012/02/image_thumb57.png?w=447&#038;h=27" width="447" height="27" /></a></p>
<p><font size="3">Where <b>in T</b> is type of input parameter and <b>T obj </b>is value passed for the parameter.</font> </p>
<p><b><u><font size="4">Action with Anonymous method</font> </u></b></p>
<p><font size="3">You can work with Action and anonymous method as well. You can assign anonymous method to Action as below,</font> </p>
<p><a href="http://dhananjay25.files.wordpress.com/2012/02/image58.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://dhananjay25.files.wordpress.com/2012/02/image_thumb58.png?w=624&#038;h=119" width="624" height="119" /></a></p>
<p><font size="3">Above code will print 9 as output.</font> </p>
<p><b><u><font size="4">Action with Lambda Expression</font> </u></b></p>
<p><font size="3">Like any other delegates, Action can be worked with lambda expression also as below,</font> </p>
<p><a href="http://dhananjay25.files.wordpress.com/2012/02/image59.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://dhananjay25.files.wordpress.com/2012/02/image_thumb59.png?w=525&#038;h=137" width="525" height="137" /></a></p>
<p><font size="3">Above code will also print 9 as output.</font> </p>
<p><b><u><font size="4">Passing Action as input parameter</font> </u></b></p>
<p><font size="3">You can pass Action as parameter of a function also. Let us say you have a class</font> </p>
<p><a href="http://dhananjay25.files.wordpress.com/2012/02/image60.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://dhananjay25.files.wordpress.com/2012/02/image_thumb60.png?w=456&#038;h=139" width="456" height="139" /></a></p>
<p><font size="3">And two functions called <b>Display</b> and <b>Show</b> to display <b>Name</b> and <b>RollNumber</b> of Student.</font> </p>
<p><a href="http://dhananjay25.files.wordpress.com/2012/02/image61.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://dhananjay25.files.wordpress.com/2012/02/image_thumb61.png?w=524&#038;h=263" width="524" height="263" /></a></p>
<p><font size="3">Now you got a function where you need to pass either Display or Show. Or in other words you need to pass any function with the same signature of Display or Show. In that case you will be passing a delegate as input parameter to the function.</font> </p>
<p><a href="http://dhananjay25.files.wordpress.com/2012/02/image62.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://dhananjay25.files.wordpress.com/2012/02/image_thumb62.png?w=624&#038;h=118" width="624" height="118" /></a></p>
<p><font size="3">You can call <b>CallingAction</b> method in Main as below,</font> </p>
<p><a href="http://dhananjay25.files.wordpress.com/2012/02/image63.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;margin:5px;" title="image" border="0" alt="image" src="http://dhananjay25.files.wordpress.com/2012/02/image_thumb63.png?w=624&#038;h=237" width="624" height="237" /></a></p>
<p><font size="3">Above we are creating instance of Student class and one by one passing Display function and Show function as input parameter to <b>CallingAction</b> function. In CallingAction function, we are printing name of the function being passed as input parameter. On running you will get below output.</font> </p>
<p><a href="http://dhananjay25.files.wordpress.com/2012/02/image64.png"><img style="background-image:none;border-bottom:0;border-left:0;padding-left:0;padding-right:0;display:inline;border-top:0;border-right:0;padding-top:0;" title="image" border="0" alt="image" src="http://dhananjay25.files.wordpress.com/2012/02/image_thumb64.png?w=232&#038;h=147" width="232" height="147" /></a></p>
<p><font size="3">I hope now you would be able to answer what is Action in simple words. I hope this post is useful. Thanks for reading.</font> </p>
<p>&#160;</p>
<a href='http://twitter.com/debug_mode' class='twitter-follow-button' data-text-color='#555555' data-link-color='#0066cc'>Follow @debug_mode</a>
<br />Filed under: <a href='http://debugmode.net/category/csharp/'>CSharp</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dhananjay25.wordpress.com/9806/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dhananjay25.wordpress.com/9806/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dhananjay25.wordpress.com/9806/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dhananjay25.wordpress.com/9806/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dhananjay25.wordpress.com/9806/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dhananjay25.wordpress.com/9806/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dhananjay25.wordpress.com/9806/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dhananjay25.wordpress.com/9806/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dhananjay25.wordpress.com/9806/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dhananjay25.wordpress.com/9806/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dhananjay25.wordpress.com/9806/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dhananjay25.wordpress.com/9806/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=debugmode.net&#038;blog=10538757&#038;post=9806&#038;subd=dhananjay25&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://debugmode.net/2012/02/20/csharp-interview-question-what-is-action-in-csharp/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c90eb841e3efad072a72427a27409cd1?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">dhananjay25</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2012/02/image_thumb54.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2012/02/image_thumb55.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2012/02/clip_image002_thumb1.jpg" medium="image">
			<media:title type="html">clip_image002</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2012/02/image_thumb56.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2012/02/image_thumb57.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2012/02/image_thumb58.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2012/02/image_thumb59.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2012/02/image_thumb60.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2012/02/image_thumb61.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2012/02/image_thumb62.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2012/02/image_thumb63.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2012/02/image_thumb64.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>MongoDB with CSharp</title>
		<link>http://debugmode.net/2012/01/22/mongodb-with-csharp/</link>
		<comments>http://debugmode.net/2012/01/22/mongodb-with-csharp/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 11:43:46 +0000</pubDate>
		<dc:creator>Dhananjay Kumar</dc:creator>
				<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[CRUD Operation]]></category>
		<category><![CDATA[Csahrp]]></category>
		<category><![CDATA[MongoDB]]></category>

		<guid isPermaLink="false">https://dhananjay25.wordpress.com/?p=9463</guid>
		<description><![CDATA[Before you start working with MongoDB using C Sharp, I recommend you to read MongoDB on Windows quick start in 5 minute and download MongoDB for CSharp from here Start MongoDB server If you would have gone through MongoDB on<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://debugmode.net/2012/01/22/mongodb-with-csharp/">Read more &#8250;</a></div><!-- end of .read-more --><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=debugmode.net&#038;blog=10538757&#038;post=9463&#038;subd=dhananjay25&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><span style="font-size:small;">Before you start working with MongoDB using C Sharp, I recommend you to read </span><a href="http://debugmode.net/2012/01/21/mongodb-on-windows-quick-start-in-5-minute/"><span style="font-size:small;">MongoDB on Windows quick start in 5 minute</span></a><span style="font-size:small;"> and download </span><a href="https://github.com/samus/mongodb-csharp"><span style="font-size:small;">MongoDB for CSharp from here </span></a></p>
<p><strong><span style="text-decoration:underline;"><span style="font-size:medium;">Start MongoDB server</span> </span></strong></p>
<p><span style="font-size:small;">If you would have gone through </span><a href="http://debugmode.net/2012/01/21/mongodb-on-windows-quick-start-in-5-minute/"><span style="font-size:small;">MongoDB on Windows quick start in 5 minute</span></a><span style="font-size:small;"> then you know how to start MongoDB server. However just for quick recap you need to start MongoDB server as below, </span></p>
<p><span style="font-size:small;">You can connect to MongoDB server as below by executing <strong>mongod</strong> exe</span></p>
<p><a href="http://dhananjay25.files.wordpress.com/2012/01/image55.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;margin:5px;" title="image" src="http://dhananjay25.files.wordpress.com/2012/01/image_thumb55.png?w=503&#038;h=163" alt="image" width="503" height="163" border="0" /></a></p>
<p><span style="font-size:small;">By default MongoDB stores data inside data folder of C Drive. You need to explicitly create this folder as well.</span></p>
<p><strong><span style="text-decoration:underline;"><span style="font-size:medium;">Add required library in solution</span> </span></strong></p>
<p><span style="font-size:small;">You will get a solution when you download </span><a href="https://github.com/samus/mongodb-csharp"><span style="font-size:small;">MongoDB for CSharp from here </span></a><span style="font-size:small;">. Open the solution in Visual Studio and build it.</span></p>
<p><a href="http://dhananjay25.files.wordpress.com/2012/01/image56.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;margin:5px;" title="image" src="http://dhananjay25.files.wordpress.com/2012/01/image_thumb56.png?w=623&#038;h=100" alt="image" width="623" height="100" border="0" /></a></p>
<p><span style="font-size:small;">Take MongoDB.dll and add this reference to your project.</span></p>
<p><strong><span style="text-decoration:underline;"><span style="font-size:medium;">Create Project and perform operations</span></span></strong></p>
<p><span style="font-size:small;">For purpose of this blog post, I am going to create a console application. I have added MongoDB.dll as reference in console application project.</span></p>
<p><strong><span style="text-decoration:underline;"><span style="font-size:small;">Create DataBase</span></span></strong></p>
<p><span style="font-size:small;">If you want to <strong>create a database</strong>, you can create as below,</span></p>
<p><a href="http://dhananjay25.files.wordpress.com/2012/01/clip_image00213.jpg"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="clip_image002" src="http://dhananjay25.files.wordpress.com/2012/01/clip_image002_thumb9.jpg?w=624&#038;h=77" alt="clip_image002" width="624" height="77" border="0" /></a></p>
<p><span style="font-size:small;">Above code will connect to MongoDB and create a database called Bloggers, if it does not exist.</span></p>
<p><strong><span style="text-decoration:underline;"><span style="font-size:small;">Add Record in DataBase</span> </span></strong></p>
<p><span style="font-size:small;">You can add record as below, </span></p>
<p><a href="http://dhananjay25.files.wordpress.com/2012/01/clip_image00263.jpg"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="clip_image002[6]" src="http://dhananjay25.files.wordpress.com/2012/01/clip_image0026_thumb2.jpg?w=332&#038;h=226" alt="clip_image002[6]" width="332" height="226" border="0" /></a></p>
<p><span style="font-size:small;">Where blogger is collection you get over database as below,</span></p>
<p><a href="http://dhananjay25.files.wordpress.com/2012/01/clip_image0044.jpg"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="clip_image004" src="http://dhananjay25.files.wordpress.com/2012/01/clip_image004_thumb4.jpg?w=623&#038;h=36" alt="clip_image004" width="623" height="36" border="0" /></a></p>
<p><strong><span style="text-decoration:underline;"><span style="font-size:small;">Delete Record from DataBase</span></span></strong></p>
<p><a href="http://dhananjay25.files.wordpress.com/2012/01/image57.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://dhananjay25.files.wordpress.com/2012/01/image_thumb57.png?w=356&#038;h=139" alt="image" width="356" height="139" border="0" /></a></p>
<p><span style="font-size:small;">You can delete a record by just providing one key value as well like below,</span></p>
<p><a href="http://dhananjay25.files.wordpress.com/2012/01/image58.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://dhananjay25.files.wordpress.com/2012/01/image_thumb58.png?w=342&#038;h=115" alt="image" width="342" height="115" border="0" /></a></p>
<p><strong><span style="text-decoration:underline;"><span style="font-size:small;">Fetch a Record</span> </span></strong></p>
<p><span style="font-size:small;">To fetch a particular document or record you need to create document and provide key value as below.</span></p>
<p><a href="http://dhananjay25.files.wordpress.com/2012/01/image59.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://dhananjay25.files.wordpress.com/2012/01/image_thumb59.png?w=624&#038;h=122" alt="image" width="624" height="122" border="0" /></a></p>
<p><span style="font-size:small;">FindOne() function returns a document . You need to call Get function with key value as input to fetch the value. </span></p>
<p><span style="font-size:small;">For your reference full source code is as below,</span></p>
<pre class="brush: csharp; title: ; notranslate">

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MongoDB;

namespace ConsoleApplication34
{
class Program
{
static void Main(string[] args)
{

//Create Database
Mongo mongoDBdataBase = new Mongo();
mongoDBdataBase.Connect();
var dataBaseToWork = mongoDBdataBase.GetDatabase(&quot;Bloggers&quot;);
//Create Collection
var blogger = dataBaseToWork.GetCollection(&quot;blogger&quot;);

//Insert Records
var b = new Document();
b[&quot;Name&quot;] = &quot;Dhananjay&quot;;
b[&quot;Country&quot;] = &quot;India&quot;;
blogger.Insert(b);
b[&quot;Name&quot;] = &quot;G Block&quot;;
b[&quot;Country&quot;] = &quot;USA&quot;;
blogger.Insert(b);

//Fetch Record
var searchBlogger = new Document();
searchBlogger[&quot;Name&quot;] = &quot;Dhananjay&quot;;
var result = blogger.FindOne(searchBlogger);
Console.WriteLine(result.Get(&quot;Country&quot;).ToString());

Console.ReadKey(true);

}
}
}
</pre>
<p>In this way you can perform operations on MongoDB using CSharp. I hope this post is useful. Thanks for reading.</p>
<a href='http://twitter.com/debug_mode' class='twitter-follow-button' data-text-color='#555555' data-link-color='#0066cc'>Follow @debug_mode</a>
<br />Filed under: <a href='http://debugmode.net/category/csharp/'>CSharp</a>, <a href='http://debugmode.net/category/miscellaneous/'>Miscellaneous</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dhananjay25.wordpress.com/9463/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dhananjay25.wordpress.com/9463/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dhananjay25.wordpress.com/9463/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dhananjay25.wordpress.com/9463/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dhananjay25.wordpress.com/9463/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dhananjay25.wordpress.com/9463/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dhananjay25.wordpress.com/9463/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dhananjay25.wordpress.com/9463/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dhananjay25.wordpress.com/9463/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dhananjay25.wordpress.com/9463/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dhananjay25.wordpress.com/9463/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dhananjay25.wordpress.com/9463/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=debugmode.net&#038;blog=10538757&#038;post=9463&#038;subd=dhananjay25&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://debugmode.net/2012/01/22/mongodb-with-csharp/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c90eb841e3efad072a72427a27409cd1?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">dhananjay25</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2012/01/image_thumb55.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2012/01/image_thumb56.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2012/01/clip_image002_thumb9.jpg" medium="image">
			<media:title type="html">clip_image002</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2012/01/clip_image0026_thumb2.jpg" medium="image">
			<media:title type="html">clip_image002[6]</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2012/01/clip_image004_thumb4.jpg" medium="image">
			<media:title type="html">clip_image004</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2012/01/image_thumb57.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2012/01/image_thumb58.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2012/01/image_thumb59.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Reading EXCEL FILE in a collection using Open XML SDK 2.0</title>
		<link>http://debugmode.net/2011/10/08/reading-excel-file-in-a-collection-using-open-xml-sdk-2-0/</link>
		<comments>http://debugmode.net/2011/10/08/reading-excel-file-in-a-collection-using-open-xml-sdk-2-0/#comments</comments>
		<pubDate>Sat, 08 Oct 2011 04:52:35 +0000</pubDate>
		<dc:creator>Dhananjay Kumar</dc:creator>
				<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[open xml sdk]]></category>
		<category><![CDATA[reading open xml sdk]]></category>

		<guid isPermaLink="false">https://dhananjay25.wordpress.com/?p=7845</guid>
		<description><![CDATA[In my previous article I talked about Inserting in Excel file from C# collection using Open XML SDK 2.0 before you go ahead, I strongly recommend you to read this post. In this post, let us try to do the<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://debugmode.net/2011/10/08/reading-excel-file-in-a-collection-using-open-xml-sdk-2-0/">Read more &#8250;</a></div><!-- end of .read-more --><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=debugmode.net&#038;blog=10538757&#038;post=7845&#038;subd=dhananjay25&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>In my previous article I talked about <a href="http://debugmode.net/2011/10/04/inserting-in-excel-file-from-c-collection-using-open-xml-sdk-2-0/">Inserting in Excel file from C# collection using Open XML SDK 2.0</a> before you go ahead, I strongly recommend you to read this post.</p>
<p>In this post, let us try to do the reverse process. We will read all the rows of Excel file List of Bloggers. Again start with creating the custom class</p>
<p><strong><span style="text-decoration:underline;"><span style="color:#ff0000;">Create Entity class</span> </span></strong></p>
<p><a href="http://dhananjay25.files.wordpress.com/2011/10/image17.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;margin:5px;" title="image" src="http://dhananjay25.files.wordpress.com/2011/10/image_thumb17.png?w=487&#038;h=191" alt="image" width="487" height="191" border="0" /></a></p>
<p><strong><span style="text-decoration:underline;"><span style="color:#ff0000;">Add namespace</span></span></strong></p>
<p><a href="http://dhananjay25.files.wordpress.com/2011/10/image18.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;margin:5px;" title="image" src="http://dhananjay25.files.wordpress.com/2011/10/image_thumb18.png?w=523&#038;h=68" alt="image" width="523" height="68" border="0" /></a></p>
<p><strong><span style="text-decoration:underline;"><span style="color:#ff0000;">Setting initial code as of Excel template</span> </span></strong></p>
<p>I will walkthrough line by line of codes to make you easier for you to get a sense of the code.</p>
<p>&nbsp;</p>
<p><a href="http://dhananjay25.files.wordpress.com/2011/10/clip_image0012.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="clip_image001" src="http://dhananjay25.files.wordpress.com/2011/10/clip_image001_thumb2.png?w=501&#038;h=100" alt="clip_image001" width="501" height="100" border="0" /></a></p>
<p>In above code snippet last three lines should appear easier to you. However in first line of code you might be thinking, “Hey why string array of length 4? “ Answer of this that, if you notice our excel file it is having four columns. So in our logic we need a string array of four. If you are working with excel file with columns 10 then your string array should of size 10.</p>
<p><a href="http://dhananjay25.files.wordpress.com/2011/10/clip_image002.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="clip_image002" src="http://dhananjay25.files.wordpress.com/2011/10/clip_image002_thumb.png?w=450&#038;h=460" alt="clip_image002" width="450" height="460" border="0" /></a></p>
<p>Then I have list of bloggers and each blogger object will represent a row of the excel file.</p>
<p>&nbsp;</p>
<p><strong><span style="text-decoration:underline;"><span style="color:#ff0000;">Open Excel file</span> </span></strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><a href="http://dhananjay25.files.wordpress.com/2011/10/clip_image0031.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="clip_image003" src="http://dhananjay25.files.wordpress.com/2011/10/clip_image003_thumb1.png?w=605&#038;h=72" alt="clip_image003" width="605" height="72" border="0" /></a></p>
<p>If you have save template Excel file with different name in different location then you will have to change the location in above code.</p>
<p>If you have changed the sheet name to <strong>item</strong> then you will fetch it as below,</p>
<p><a href="http://dhananjay25.files.wordpress.com/2011/10/clip_image0052.jpg"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="clip_image005" src="http://dhananjay25.files.wordpress.com/2011/10/clip_image005_thumb2.jpg?w=623&#038;h=427" alt="clip_image005" width="623" height="427" border="0" /></a></p>
<p>&nbsp;</p>
<p>If you have not renamed the sheet and want to insert in the first sheet, you can do like below. Make note of code in comment to fetch the first sheet.</p>
<p>&nbsp;</p>
<p><a href="http://dhananjay25.files.wordpress.com/2011/10/clip_image0071.jpg"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="clip_image007" src="http://dhananjay25.files.wordpress.com/2011/10/clip_image007_thumb1.jpg?w=623&#038;h=50" alt="clip_image007" width="623" height="50" border="0" /></a></p>
<p><strong><span style="text-decoration:underline;"><span style="color:#ff0000;">Read Row by Row</span> </span></strong></p>
<p><a href="http://dhananjay25.files.wordpress.com/2011/10/clip_image008.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="clip_image008" src="http://dhananjay25.files.wordpress.com/2011/10/clip_image008_thumb.png?w=518&#038;h=259" alt="clip_image008" width="518" height="259" border="0" /></a></p>
<p>In above code snippet</p>
<ol>
<li>We are iterating through all the rows in open sheet.</li>
<li>Iterating through all the cells on selected rows.</li>
<li>There is a check because we don’t want to read first row. Since first row of the excel will contain headers not the real data.</li>
</ol>
<p>If all the cells contains numeric value then above code is suffice but there may be string or Boolean values as well. So we need to check that also as below,</p>
<p><strong><span style="text-decoration:underline;"><span style="color:#ff0000;">Checking for string cell values</span> </span></strong></p>
<p>&nbsp;</p>
<p><a href="http://dhananjay25.files.wordpress.com/2011/10/clip_image0101.jpg"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;margin:5px;" title="clip_image010" src="http://dhananjay25.files.wordpress.com/2011/10/clip_image010_thumb1.jpg?w=525&#038;h=249" alt="clip_image010" width="525" height="249" border="0" /></a></p>
<p><strong><span style="text-decoration:underline;"><span style="color:#ff0000;">Checking for Boolean cell values</span> </span></strong></p>
<p><a href="http://dhananjay25.files.wordpress.com/2011/10/clip_image011.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="clip_image011" src="http://dhananjay25.files.wordpress.com/2011/10/clip_image011_thumb.png?w=346&#038;h=249" alt="clip_image011" width="346" height="249" border="0" /></a></p>
<p>Set the value in string array as below,</p>
<p><a href="http://dhananjay25.files.wordpress.com/2011/10/clip_image012.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="clip_image012" src="http://dhananjay25.files.wordpress.com/2011/10/clip_image012_thumb.png?w=281&#038;h=59" alt="clip_image012" width="281" height="59" border="0" /></a></p>
<p>Now we need to create object of Bloggers class by values from string array.</p>
<p><a href="http://dhananjay25.files.wordpress.com/2011/10/clip_image013.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="clip_image013" src="http://dhananjay25.files.wordpress.com/2011/10/clip_image013_thumb.png?w=432&#038;h=161" alt="clip_image013" width="432" height="161" border="0" /></a></p>
<p>Consolidating all together we can create a function to read excel file</p>
<pre class="brush: csharp; title: ; notranslate">

static List&lt;Bloggers&gt; ReadExcelFileDOM(string filename)
{

string[] strProperties = new string[4];
List&lt;Bloggers&gt; lstBloggers = new List&lt;Bloggers&gt;();
Bloggers facet = null;
int j = 0;

using (SpreadsheetDocument myDoc = SpreadsheetDocument.Open(filename, true))
{
WorkbookPart workbookPart = myDoc.WorkbookPart;
IEnumerable&lt;Sheet&gt; Sheets = myDoc.WorkbookPart.Workbook.GetFirstChild&lt;Sheets&gt;().Elements&lt;Sheet&gt;().Where(s =&gt; s.Name == &quot;items&quot;);
if (Sheets.Count() == 0)
{
}
string relationshipId = Sheets.First().Id.Value;
WorksheetPart worksheetPart = (WorksheetPart)myDoc.WorkbookPart.GetPartById(relationshipId);
SheetData sheetData = worksheetPart.Worksheet.GetFirstChild&lt;SheetData&gt;();

List&lt;string&gt; lstRow = new List&lt;string&gt;();

int i = 1;
string value;
foreach (Row r in sheetData.Elements&lt;Row&gt;())
{
if (i != 1)
{
foreach (Cell c in r.Elements&lt;Cell&gt;())
{
if (c != null)
{
value = c.InnerText;

if (c.DataType != null)
{
switch (c.DataType.Value)
{
case CellValues.SharedString:
var stringTable = workbookPart.GetPartsOfType&lt;SharedStringTablePart&gt;().FirstOrDefault();
if (stringTable != null)
{
value = stringTable.SharedStringTable.
ElementAt(int.Parse(value)).InnerText;
}
break;
case CellValues.Boolean:
switch (value)
{
case &quot;0&quot;:
value = &quot;FALSE&quot;;
break;
default:
value = &quot;TRUE&quot;;
break;
}
break;
}
}

strProperties[j] = value;
j = j + 1;
}

}
}
j = 0;
&amp;nbsp;

i = i + 1;
facet = new Bloggers();
facet.Name = strProperties[0];
facet.Intrest = strProperties[1];
facet.NumberofPosts = strProperties[2];
facet.Speaker = strProperties[3];
lstFacetToInsert.Add(facet);
}

return lstFacetToInsert;
}

}

</pre>
<p>And you can make function call as below,</p>
<pre class="brush: csharp; title: ; notranslate">

List&lt;SCDataFacets&gt; result =  ReadExcelFileDOM(&quot;D:\\MyExcel.xlsx&quot;);

foreach (var a in result)
{

Console.WriteLine(a.Name);

}
Console.ReadKey(true);

</pre>
<p>This was all required to read a excel file using Open XML SDK. I hope this post was useful to you. Thanks for reading <img class="wlEmoticon wlEmoticon-smile" style="border-style:none;" src="http://dhananjay25.files.wordpress.com/2011/10/wlemoticon-smile8.png?w=605" alt="Smile" /></p>
<a href='http://twitter.com/debug_mode' class='twitter-follow-button' data-text-color='#555555' data-link-color='#0066cc'>Follow @debug_mode</a>
<p>If you find my posts useful you may like to follow me on twitter <a href="http://twitter.com/debug_mode"><strong>http://twitter.com/debug_mode</strong></a> or may like Facebook page of my blog <a href="http://www.facebook.com/DebugMode.Net"><strong>http://www.facebook.com/DebugMode.Net</strong></a> If you want to see post on a particular topic please do write on FB page or tweet me about that, I would love to help you</p>
<br />Filed under: <a href='http://debugmode.net/category/csharp/'>CSharp</a>, <a href='http://debugmode.net/category/miscellaneous/'>Miscellaneous</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dhananjay25.wordpress.com/7845/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dhananjay25.wordpress.com/7845/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dhananjay25.wordpress.com/7845/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dhananjay25.wordpress.com/7845/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dhananjay25.wordpress.com/7845/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dhananjay25.wordpress.com/7845/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dhananjay25.wordpress.com/7845/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dhananjay25.wordpress.com/7845/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dhananjay25.wordpress.com/7845/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dhananjay25.wordpress.com/7845/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dhananjay25.wordpress.com/7845/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dhananjay25.wordpress.com/7845/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=debugmode.net&#038;blog=10538757&#038;post=7845&#038;subd=dhananjay25&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://debugmode.net/2011/10/08/reading-excel-file-in-a-collection-using-open-xml-sdk-2-0/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c90eb841e3efad072a72427a27409cd1?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">dhananjay25</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2011/10/image_thumb17.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2011/10/image_thumb18.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2011/10/clip_image001_thumb2.png" medium="image">
			<media:title type="html">clip_image001</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2011/10/clip_image002_thumb.png" medium="image">
			<media:title type="html">clip_image002</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2011/10/clip_image003_thumb1.png" medium="image">
			<media:title type="html">clip_image003</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2011/10/clip_image005_thumb2.jpg" medium="image">
			<media:title type="html">clip_image005</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2011/10/clip_image007_thumb1.jpg" medium="image">
			<media:title type="html">clip_image007</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2011/10/clip_image008_thumb.png" medium="image">
			<media:title type="html">clip_image008</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2011/10/clip_image010_thumb1.jpg" medium="image">
			<media:title type="html">clip_image010</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2011/10/clip_image011_thumb.png" medium="image">
			<media:title type="html">clip_image011</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2011/10/clip_image012_thumb.png" medium="image">
			<media:title type="html">clip_image012</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2011/10/clip_image013_thumb.png" medium="image">
			<media:title type="html">clip_image013</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2011/10/wlemoticon-smile8.png" medium="image">
			<media:title type="html">Smile</media:title>
		</media:content>
	</item>
		<item>
		<title>Inserting in Excel file from C# collection using Open XML SDK 2.0</title>
		<link>http://debugmode.net/2011/10/04/inserting-in-excel-file-from-c-collection-using-open-xml-sdk-2-0/</link>
		<comments>http://debugmode.net/2011/10/04/inserting-in-excel-file-from-c-collection-using-open-xml-sdk-2-0/#comments</comments>
		<pubDate>Tue, 04 Oct 2011 01:37:15 +0000</pubDate>
		<dc:creator>Dhananjay Kumar</dc:creator>
				<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#4.0]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[open xml sdk]]></category>

		<guid isPermaLink="false">https://dhananjay25.wordpress.com/?p=7766</guid>
		<description><![CDATA[In this post I will show inserting rows in excel file from a c Sharp list using Open XML SDK. Open XML SDK is very useful when you don’t want to or cannot use Microsoft Office InterOP dll. You can<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://debugmode.net/2011/10/04/inserting-in-excel-file-from-c-collection-using-open-xml-sdk-2-0/">Read more &#8250;</a></div><!-- end of .read-more --><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=debugmode.net&#038;blog=10538757&#038;post=7766&#038;subd=dhananjay25&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>In this post I will show inserting rows in excel file from a c Sharp list using Open XML SDK. Open XML SDK is very useful when you don’t want to or cannot use Microsoft Office InterOP dll.</p>
<p>You can download it from below URL</p>
<p><a href="http://www.microsoft.com/download/en/details.aspx?id=5124">http://www.microsoft.com/download/en/details.aspx?id=5124</a></p>
<p>Once you download and run the MSI follow the below steps.</p>
<p><strong><span style="text-decoration:underline;"><span style="color:#0000ff;">Creating Data Source to be inserted in excel</span> </span></strong></p>
<p>Let us say you have class as below,</p>
<p><a href="http://dhananjay25.files.wordpress.com/2011/10/image3.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;margin:5px;" title="image" src="http://dhananjay25.files.wordpress.com/2011/10/image_thumb3.png?w=567&#038;h=222" alt="image" width="567" height="222" border="0" /></a></p>
<p>And below function returning list of bloggers. We are going to insert all the items from this list in Excel file.</p>
<pre class="brush: csharp; title: ; notranslate">

private List&lt;Bloggers&gt; GetDataToInsertInExcel()
{
List&lt;Bloggers&gt; lstBloggers = new List&lt;Bloggers&gt;
{
new Bloggers
{
Name = &quot;Pinal Dave&quot;,
Interest = &quot;SQL Server&quot;,
NumberofPosts = 1500,
Speaker = true
},
new Bloggers
{
Name = &quot;Mahesh Chand&quot;,
Interest = &quot;C Sharp&quot;,
NumberofPosts = 1300,
Speaker = true
},
new Bloggers
{
Name = &quot;Debug Mode&quot;,
Interest = &quot;all&quot;,
NumberofPosts = 400,
Speaker = false
},
new Bloggers
{
Name = &quot;Shiv Prasad Koirala&quot;,
Interest = &quot;ASp.Net&quot;,
NumberofPosts = 500,
Speaker = true
},
new Bloggers
{
Name = &quot;Anoop Madusudhan&quot;,
Interest = &quot;WCF&quot;,
NumberofPosts = 500,
Speaker = false
},
};
return lstBloggers;
}

&amp;nbsp;

&amp;nbsp;

</pre>
<p>You are very much free to change data source to</p>
<ul>
<li>Azure table</li>
<li>SQL Server table</li>
<li>SQL Azure table</li>
</ul>
<p>Theoretically you can use any data source provided you are converting the result in List. If you are using SQL Server or SQL Azure, you can use LINQ to SQL to create data source.</p>
<p>Since now we have data source, let us insert the items of list in the excel file using open xml SDK.</p>
<p><strong><span style="text-decoration:underline;"><span style="color:#0000ff;">Add Namespaces</span> </span></strong></p>
<p>You need to add below namespaces,</p>
<p><a href="http://dhananjay25.files.wordpress.com/2011/10/image4.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://dhananjay25.files.wordpress.com/2011/10/image_thumb4.png?w=577&#038;h=75" alt="image" width="577" height="75" border="0" /></a></p>
<p><strong><span style="text-decoration:underline;"><span style="color:#0000ff;">Have a Template</span> </span></strong></p>
<p>If you notice we have four properties in entity class. So there would be four columns in the excel sheet. Save an excel file with any name of your preference at any location of your preference. For purpose of this article I am saving it to the</p>
<p><a href="http://dhananjay25.files.wordpress.com/2011/10/image5.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://dhananjay25.files.wordpress.com/2011/10/image_thumb5.png?w=450&#038;h=460" alt="image" width="450" height="460" border="0" /></a></p>
<p>There are three points worth noticing about the template</p>
<ol>
<li>All the columns [properties of entity class] is in first row in columns A, B,C,D</li>
<li>Sheet is renamed to items. If you want you can have default name.</li>
<li>Template excel file with name <strong><span style="color:#ff0000;">testupload</span></strong> is in d drive.</li>
</ol>
<p><strong><span style="text-decoration:underline;"><span style="color:#0000ff;">Opening the template file to insert rows</span> </span></strong></p>
<p>&nbsp;</p>
<p><a href="http://dhananjay25.files.wordpress.com/2011/10/image6.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://dhananjay25.files.wordpress.com/2011/10/image_thumb6.png?w=605&#038;h=72" alt="image" width="605" height="72" border="0" /></a></p>
<p>If you have save template Excel file with different name in different location then you will have to change the location in above code.</p>
<p>If you have changed the sheet name to <strong>item</strong> then you will fetch it as below,</p>
<p>&nbsp;</p>
<p><a href="http://dhananjay25.files.wordpress.com/2011/10/image7.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://dhananjay25.files.wordpress.com/2011/10/image_thumb7.png?w=623&#038;h=427" alt="image" width="623" height="427" border="0" /></a></p>
<p>&nbsp;</p>
<p>If you have not renamed the sheet and want to insert in the first sheet, you can do like below. Make note of code in comment to fetch the first sheet.</p>
<p>&nbsp;</p>
<p><a href="http://dhananjay25.files.wordpress.com/2011/10/image8.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://dhananjay25.files.wordpress.com/2011/10/image_thumb8.png?w=623&#038;h=50" alt="image" width="623" height="50" border="0" /></a></p>
<p><strong><span style="text-decoration:underline;"><span style="color:#0000ff;">Inserting the rows</span></span></strong></p>
<p>Now document is open, so we need to insert rows one by one. So we will loop through all the items in list and call a function to create row. On successful return of the row from function we will append it to the open sheet.</p>
<p><a href="http://dhananjay25.files.wordpress.com/2011/10/image9.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://dhananjay25.files.wordpress.com/2011/10/image_thumb9.png?w=624&#038;h=300" alt="image" width="624" height="300" border="0" /></a></p>
<p>If you notice above code snippet I have initialized index value to 2 because in first row of the excel sheet, we are putting the header. From second row onward items in each row would get inserted. I am making call to <strong>CreateContentRow</strong> function.</p>
<p><strong><span style="text-decoration:underline;"><span style="color:#0000ff;">Creating the rows</span></span></strong></p>
<p>&nbsp;</p>
<p><a href="http://dhananjay25.files.wordpress.com/2011/10/image10.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://dhananjay25.files.wordpress.com/2011/10/image_thumb10.png?w=623&#038;h=292" alt="image" width="623" height="292" border="0" /></a></p>
<p><strong><span style="color:#ff0000;">In you notice above that in header columns string array, we are starting from A to D. It is because we have only four columns to insert. If you have 6 columns to insert then string array would be from A to F.</span></strong></p>
<p>&nbsp;</p>
<p>In above snippet I am iterating through all the properties of the entity object and creating cell reference by appending index with column headers.</p>
<p>Next I need to find type of property .There may be three types</p>
<ol>
<li>String <strong></strong></li>
<li>Integer <strong></strong></li>
<li>Boolean <strong></strong></li>
</ol>
<p>We need to check for the type of property and then create the cell to insert the value</p>
<p><strong><span style="text-decoration:underline;"><span style="color:#0000ff;">Checking for String</span></span></strong></p>
<p><a href="http://dhananjay25.files.wordpress.com/2011/10/image11.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://dhananjay25.files.wordpress.com/2011/10/image_thumb11.png?w=624&#038;h=369" alt="image" width="624" height="369" border="0" /></a></p>
<p><strong><span style="text-decoration:underline;"><span style="color:#0000ff;">Checking for Integer</span></span></strong></p>
<p>&nbsp;</p>
<p><a href="http://dhananjay25.files.wordpress.com/2011/10/image12.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://dhananjay25.files.wordpress.com/2011/10/image_thumb12.png?w=624&#038;h=273" alt="image" width="624" height="273" border="0" /></a></p>
<p><strong><span style="text-decoration:underline;"><span style="color:#0000ff;">Checking for Boolean</span></span></strong></p>
<p><a href="http://dhananjay25.files.wordpress.com/2011/10/image13.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;margin:5px;" title="image" src="http://dhananjay25.files.wordpress.com/2011/10/image_thumb13.png?w=624&#038;h=304" alt="image" width="624" height="304" border="0" /></a></p>
<p>Putting all together all pieces of codes we discussed above, for your reference whole source code is as below,</p>
<pre class="brush: csharp; title: ; notranslate">

using System;
using System.Collections.Generic;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;

namespace ConsoleApplication28
{
class Program
{
static void Main(string[] args)
{
CreatingAndUploadingExcel();
}
Public static bool CreatingAndUploadingExcel()
{

using (SpreadsheetDocument myWorkbook = SpreadsheetDocument.Open(&quot;d:\\LocalCollection.xlsx&quot;, true))
{
//WorksheetPart worksheetPart = workbookPart.WorksheetParts.First();

WorkbookPart workbookPart = myWorkbook.WorkbookPart;

IEnumerable&lt;Sheet&gt; Sheets = myWorkbook.WorkbookPart.Workbook.GetFirstChild&lt;Sheets&gt;().Elements&lt;Sheet&gt;().Where(s=&gt;s.Name==&quot;items&quot;);
if (Sheets.Count() == 0)
{
// The specified worksheet does not exist.
return false;
}

string relationshipId = Sheets.First().Id.Value;
WorksheetPart worksheetPart = (WorksheetPart)myWorkbook.WorkbookPart.GetPartById(relationshipId);
SheetData sheetData = worksheetPart.Worksheet.GetFirstChild&lt;SheetData&gt;();

int index = 2;
foreach (var entity in GetDataToInsertInExcel())
{

Row contentRow = CreateContentRow(index, entity);
index++;
sheetData.AppendChild(contentRow);
}

workbookPart.Workbook.Save();

}

}
string[] headerColumns = new string[] { &quot;A&quot;, &quot;B&quot;,&quot;C&quot;,&quot;D&quot;};
private Row CreateContentRow(int index, Bloggers objToInsert)
{

Row r = new Row ();
r.RowIndex = (UInt32) index;
int i = 0;

foreach (var prop in objToInsert.GetType().GetProperties())
{
Cell c = new Cell();
c.CellReference = headerColumns[i].ToString() + index;

if (prop.PropertyType.ToString().Equals(&quot;System.string&quot;, StringComparison.InvariantCultureIgnoreCase))
{

var result = prop.GetValue(objToInsert, null);

if (result == null)
{
result = &quot;&quot;;
}

c.DataType = CellValues.String;
InlineString inlineString = new InlineString();
Text t = new Text();
t.Text = result.ToString();
inlineString.AppendChild(t);
c.AppendChild(inlineString);

}

if (prop.PropertyType.ToString().Equals(&quot;System.int32&quot;, StringComparison.InvariantCultureIgnoreCase))
{

var result = prop.GetValue(objToInsert, null);
if (result == null)
{
result = 0;
}

CellValue v = new CellValue();
v.Text = result.ToString();
c.AppendChild(v);

}

if (prop.PropertyType.ToString().Equals(&quot;System.boolean&quot;, StringComparison.InvariantCultureIgnoreCase))
{

var result = prop.GetValue(objToInsert, null);
if (result == null)
{
result = &quot;False&quot;;
}
c.DataType = CellValues.InlineString;
InlineString inlineString = new InlineString();
Text t = new Text();
t.Text = result.ToString();
inlineString.AppendChild(t);
c.AppendChild(inlineString);

}


r.AppendChild(c);
i = i + 1;
}

return r;

}
private List&lt;Bloggers&gt; GetDataToInsertInExcel()
{
List&lt;Bloggers&gt; lstBloggers = new List&lt;Bloggers&gt;
{
new Bloggers
{
Name = &quot;Pinal Dave&quot;,
Interest = &quot;SQL Server&quot;,
NumberofPosts = 1500,
Speaker = true
},
new Bloggers
{
Name = &quot;Mahesh Chand&quot;,
Interest = &quot;C Sharp&quot;,
NumberofPosts = 1300,
Speaker = true
},
new Bloggers
{
Name = &quot;Debug Mode&quot;,
Interest = &quot;all&quot;,
NumberofPosts = 400,
Speaker = false
},
new Bloggers
{
Name = &quot;Shiv Prasad Koirala&quot;,
Interest = &quot;ASp.Net&quot;,
NumberofPosts = 500,
Speaker = true
},
new Bloggers
{
Name = &quot;Anoop Madusudhan&quot;,
Interest = &quot;WCF&quot;,
NumberofPosts = 500,
Speaker = false
},
};
return lstBloggers;
}

}

}

public class Bloggers
{
public string Name { get; set; }
public string Interest { get; set; }
public int NumberofPosts { get; set; }
public bool Speaker { get; set; }
}

}

</pre>
<p>Now go ahead and open Excel file and you should get the row inserted. I hope this post was useful. Thanks for reading <img class="wlEmoticon wlEmoticon-smile" style="border-style:none;" src="http://dhananjay25.files.wordpress.com/2011/10/wlemoticon-smile3.png?w=605" alt="Smile" /></p>
<p>If you find my posts useful you may like to follow me on twitter <a href="http://twitter.com/debug_mode"><strong>http://twitter.com/debug_mode</strong></a> or may like Facebook page of my blog <a href="http://www.facebook.com/DebugMode.Net"><strong>http://www.facebook.com/DebugMode.Net</strong></a> If you want to see post on a particular topic please do write on FB page or tweet me about that, I would love to help you.</p>
<p>&nbsp;</p>
<a href='http://twitter.com/debug_mode' class='twitter-follow-button' data-text-color='#555555' data-link-color='#0066cc'>Follow @debug_mode</a>
<br />Filed under: <a href='http://debugmode.net/category/csharp/'>CSharp</a>, <a href='http://debugmode.net/category/miscellaneous/'>Miscellaneous</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dhananjay25.wordpress.com/7766/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dhananjay25.wordpress.com/7766/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dhananjay25.wordpress.com/7766/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dhananjay25.wordpress.com/7766/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dhananjay25.wordpress.com/7766/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dhananjay25.wordpress.com/7766/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dhananjay25.wordpress.com/7766/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dhananjay25.wordpress.com/7766/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dhananjay25.wordpress.com/7766/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dhananjay25.wordpress.com/7766/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dhananjay25.wordpress.com/7766/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dhananjay25.wordpress.com/7766/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=debugmode.net&#038;blog=10538757&#038;post=7766&#038;subd=dhananjay25&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://debugmode.net/2011/10/04/inserting-in-excel-file-from-c-collection-using-open-xml-sdk-2-0/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c90eb841e3efad072a72427a27409cd1?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">dhananjay25</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2011/10/image_thumb3.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2011/10/image_thumb4.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2011/10/image_thumb5.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2011/10/image_thumb6.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2011/10/image_thumb7.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2011/10/image_thumb8.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2011/10/image_thumb9.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2011/10/image_thumb10.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2011/10/image_thumb11.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2011/10/image_thumb12.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2011/10/image_thumb13.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2011/10/wlemoticon-smile3.png" medium="image">
			<media:title type="html">Smile</media:title>
		</media:content>
	</item>
		<item>
		<title>Code snippet for Fetching Data from Excel using ADO.Net</title>
		<link>http://debugmode.net/2011/06/03/code-snippet-for-fetching-data-from-excel-using-ado-net/</link>
		<comments>http://debugmode.net/2011/06/03/code-snippet-for-fetching-data-from-excel-using-ado-net/#comments</comments>
		<pubDate>Fri, 03 Jun 2011 16:48:04 +0000</pubDate>
		<dc:creator>Dhananjay Kumar</dc:creator>
				<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[ADO.Net]]></category>
		<category><![CDATA[REading Excel]]></category>

		<guid isPermaLink="false">https://dhananjay25.wordpress.com/?p=5915</guid>
		<description><![CDATA[Today one of my team members asked me a very simple question though very important question, “How could we fetch Excel Records using ADO.Net? Could you give me code snippet of same? “ I replied him; it is pretty possible<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://debugmode.net/2011/06/03/code-snippet-for-fetching-data-from-excel-using-ado-net/">Read more &#8250;</a></div><!-- end of .read-more --><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=debugmode.net&#038;blog=10538757&#038;post=5915&#038;subd=dhananjay25&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Today one of my team members asked me a very simple question though very important question,</p>
<p><em>“How could we fetch Excel Records using ADO.Net? Could you give me code snippet of same? “ </em></p>
<p>I replied him; it is pretty possible using <strong>oledDbConnection</strong>  <img class="wlEmoticon wlEmoticon-smile" style="border-style:none;" src="http://dhananjay25.files.wordpress.com/2011/06/wlemoticon-smile1.png?w=605" alt="Smile" /></p>
<p>I told him to add below reference</p>
<p><a href="http://dhananjay25.files.wordpress.com/2011/06/image6.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://dhananjay25.files.wordpress.com/2011/06/image_thumb6.png?w=277&#038;h=56" alt="image" width="277" height="56" border="0" /></a></p>
<p>I gave him below straight forward code snippet. This function is</p>
<ol>
<li>Returning DataTable</li>
<li>Reading XLS file from called <strong>YourFile.xls</strong> from <strong>F Drive</strong>.</li>
<li>Reading Sheet1</li>
</ol>
<pre class="brush: csharp; title: ; notranslate">
public static  DataTable  GetItemsFromExcel1()
       {

           List&lt;Items&gt; lstItems = new List&lt;Items&gt;();
           Items item;
           DataTable dt = new DataTable();

           OleDbConnection excelConnection = new OleDbConnection (@&quot;Provider=Microsoft.Jet.OLEDB.4.0;&quot;
                                                + @&quot;Data Source=F:\YourFile.xls;&quot;
                                                + @&quot;Extended Properties=&quot;&quot;Excel 8.0;HDR=Yes;IMEX=1;&quot;&quot;&quot;);

           excelConnection.Open();
           try
           {
               OleDbDataAdapter dbAdapter =
                   new OleDbDataAdapter
                       (&quot;SELECT * FROM [Sheet1$]&quot;, excelConnection);
               dbAdapter.Fill(dt);
           }
           finally
           {
               excelConnection.Close();
           }

return dt;
}

</pre>
<p>After using this function in his code , he was very happy and paid my coffee bill  <img class="wlEmoticon wlEmoticon-smile" style="border-style:none;" src="http://dhananjay25.files.wordpress.com/2011/06/wlemoticon-smile1.png?w=605" alt="Smile" /></p>
<a href='http://twitter.com/debugmode_' class='twitter-follow-button' data-text-color='#555555' data-link-color='#0066cc'>Follow @debugmode_</a>
<br />Filed under: <a href='http://debugmode.net/category/csharp/'>CSharp</a>, <a href='http://debugmode.net/category/miscellaneous/'>Miscellaneous</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dhananjay25.wordpress.com/5915/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dhananjay25.wordpress.com/5915/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dhananjay25.wordpress.com/5915/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dhananjay25.wordpress.com/5915/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dhananjay25.wordpress.com/5915/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dhananjay25.wordpress.com/5915/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dhananjay25.wordpress.com/5915/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dhananjay25.wordpress.com/5915/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dhananjay25.wordpress.com/5915/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dhananjay25.wordpress.com/5915/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dhananjay25.wordpress.com/5915/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dhananjay25.wordpress.com/5915/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=debugmode.net&#038;blog=10538757&#038;post=5915&#038;subd=dhananjay25&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://debugmode.net/2011/06/03/code-snippet-for-fetching-data-from-excel-using-ado-net/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c90eb841e3efad072a72427a27409cd1?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">dhananjay25</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2011/06/wlemoticon-smile1.png" medium="image">
			<media:title type="html">Smile</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2011/06/image_thumb6.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://dhananjay25.files.wordpress.com/2011/06/wlemoticon-smile1.png" medium="image">
			<media:title type="html">Smile</media:title>
		</media:content>
	</item>
	</channel>
</rss>
