<?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>C# &#8211; Sibeesh Passion</title>
	<atom:link href="https://sibeeshpassion.com/category/csharp/feed/" rel="self" type="application/rss+xml" />
	<link>https://sibeeshpassion.com</link>
	<description>My passion towards life</description>
	<lastBuildDate>Wed, 02 Jun 2021 15:17:08 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>/wp-content/uploads/2017/04/Sibeesh_Passion_Logo_Small.png</url>
	<title>C# &#8211; Sibeesh Passion</title>
	<link>https://sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>LINQ Basic To Advanced &#8211; MVC Demo Application</title>
		<link>https://sibeeshpassion.com/linq-basic-to-advanced-mvc-demo-application/</link>
					<comments>https://sibeeshpassion.com/linq-basic-to-advanced-mvc-demo-application/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Mon, 15 May 2017 16:09:40 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[LINQ Queries]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=12365</guid>

					<description><![CDATA[[toc] Introduction Here, in this post we are going to a see some LINQ queries, which covers both basics and advanced. LINQ queries are introduced few years back to offer a consistent way for working with data across many datasources and formats. In LINQ queries, you will always work with objects, which makes it simple to write. I hope you would have already written lots of LINQ queries already, if you haven&#8217;t, I strongly reccommend you to read this blog where you can find the answer for, why do we need to use LINQ?. Here I am going to create [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[toc]</p>
<h3>Introduction</h3>
<p>Here, in this post we are going to a see some <a href="http://sibeeshpassion.com/tag/LINQ" target="_blank" rel="noopener noreferrer">LINQ</a> queries, which covers both basics and advanced. LINQ queries are introduced few years back to offer a consistent way for working with data across many datasources and formats. In LINQ queries, you will always work with objects, which makes it simple to write. I hope you would have already written lots of LINQ queries already, if you haven&#8217;t, I strongly reccommend you to read this <a href="https://docs.microsoft.com/en-us/dotnet/articles/csharp/programming-guide/concepts/linq/introduction-to-linq-queries" target="_blank" rel="noopener">blog </a> where you can find the answer for, why do we need to use LINQ?. Here I am going to create a <a href="http://sibeeshpassion.com/category/mvc/">MVC</a> demo application. I hope you will like this. Now let&#8217;s begin.</p>
<h3>Download Source Code</h3>
<li><a href="https://code.msdn.microsoft.com/LINQ-Basic-To-Advanced-MVC-cc3b8254" target="_blank" rel="noopener">LINQ_B_To_A</a></li>
<h3>Background</h3>
<p>Whenever I get a chance to write some server side codes in <a href="http://sibeeshpassion.com/category/csharp/" target="_blank" rel="noopener">C#</a>, I always write it using LINQ. And few weeks back, I was assigned to a training programme where my job was to teach LINQ, hence this post covers the the queries I have written for the training programme. Hope you will find it useful.</p>
<h3>Using the code</h3>
<p>A LINQ query can be written in two ways.</p>
<li>Query Syntax</li>
<li>Method Chain or Using dot(.) operator</li>
<p>There are so many articles available in the Internet on the topic LINQ, but most of them dont cover the differences of writing the queries in two possible ways, the motive of this article is to write the queries in both ways, so that you can understand the differnces.</p>
<p>As I mentioned, we are going to create an MVC application, we need to create it first and then configure the entity. Let&#8217;s go and do that.</p>
<h4>Create a database</h4>
<p>To get started with we need to configure our database first. To do so, either you can download the Wild World Importers from <a href="https://github.com/Microsoft/sql-server-samples/releases/tag/wide-world-importers-v1.0" target="_blank" rel="noopener">here</a> or you can run the script file included in the downlaod link above. </p>
<p>Once after you created the database, you can create your MVC application and Entity Data Model in it. </p>
<h4>Configuring MVC application with Entity Data Model</h4>
<p>By this time, I hope you would have configured your MVC application with Entity Data Model. Now it is time to create a controller and Entity object. </p>
<p>[csharp]<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Data.Entity;<br />
using System.Linq;<br />
using System.Web;<br />
using System.Web.Mvc;<br />
using System.Windows.Forms;<br />
using LINQ_B_to_A.Models;<br />
namespace LINQ_B_to_A.Controllers<br />
{<br />
    public class HomeController : Controller<br />
    {<br />
        // GET: Home</p>
<p>        public MyDataModel DtContext { get; set; } = new MyDataModel();<br />
    }<br />
}<br />
[/csharp]</p>
<p>Now we can write some LINQ queries as everything is set to get started.</p>
<h4>Setting up the Index view with possible actions</h4>
<p>This is just to call the actions we are going write. Let&#8217;s see the Index page now. </p>
<p>[html]<br />
@{<br />
    ViewBag.Title = &quot;Index&quot;;<br />
    Layout = &quot;~/Views/Shared/_Layout.cshtml&quot;;<br />
}</p>
<p>&lt;h2&gt;Index&lt;/h2&gt;<br />
&lt;input type=&quot;button&quot; class=&quot;btn-info&quot; onclick=&quot;location.href=&#8217;@Url.Action(&quot;LoadAll&quot;,&quot;Home&quot;)&#8217;&quot; value=&quot;Load All &#8211; Query Expression&quot;/&gt;<br />
&lt;input type=&quot;button&quot; class=&quot;btn-info&quot; onclick=&quot;location.href=&#8217;@Url.Action(&quot;JoinWithWhere&quot;,&quot;Home&quot;)&#8217;&quot; value=&quot;Join With Where&quot; /&gt;<br />
&lt;input type=&quot;button&quot; class=&quot;btn-info&quot; onclick=&quot;location.href=&#8217;@Url.Action(&quot;LeftJoin&quot;,&quot;Home&quot;)&#8217;&quot; value=&quot;Left Join&quot; /&gt;<br />
&lt;input type=&quot;button&quot; class=&quot;btn-info&quot; onclick=&quot;location.href=&#8217;@Url.Action(&quot;DistinctSample&quot;,&quot;Home&quot;)&#8217;&quot; value=&quot;Distinct Sample&quot; /&gt;<br />
&lt;input type=&quot;button&quot; class=&quot;btn-info&quot; onclick=&quot;location.href=&#8217;@Url.Action(&quot;EqualsSamples&quot;,&quot;Home&quot;)&#8217;&quot; value=&quot;Equals Sample&quot; /&gt;<br />
&lt;input type=&quot;button&quot; class=&quot;btn-info&quot; onclick=&quot;location.href=&#8217;@Url.Action(&quot;NotEqualsSamples&quot;,&quot;Home&quot;)&#8217;&quot; value=&quot;Not Equals&quot; /&gt;<br />
&lt;input type=&quot;button&quot; class=&quot;btn-info&quot; onclick=&quot;location.href=&#8217;@Url.Action(&quot;PagingQueries&quot;,&quot;Home&quot;)&#8217;&quot; value=&quot;Paging Queries&quot; /&gt;<br />
&lt;input type=&quot;button&quot; class=&quot;btn-info&quot; onclick=&quot;location.href=&#8217;@Url.Action(&quot;MathQueries&quot;,&quot;Home&quot;)&#8217;&quot; value=&quot;Math Queries&quot; /&gt;<br />
&lt;input type=&quot;button&quot; class=&quot;btn-info&quot; onclick=&quot;location.href=&#8217;@Url.Action(&quot;StringQueries&quot;,&quot;Home&quot;)&#8217;&quot; value=&quot;String Queries&quot; /&gt;<br />
&lt;input type=&quot;button&quot; class=&quot;btn-info&quot; onclick=&quot;location.href=&#8217;@Url.Action(&quot;SelectMany&quot;,&quot;Home&quot;)&#8217;&quot; value=&quot;Select Many&quot; /&gt;<br />
[/html]</p>
<div id="attachment_12367" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Index-View-e1494741059608.png"><img fetchpriority="high" decoding="async" aria-describedby="caption-attachment-12367" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Index-View-e1494741059608.png" alt="LINQ Basic to Advanced Index View" width="634" height="197" class="size-full wp-image-12367" srcset="/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Index-View-e1494741059608.png 634w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Index-View-e1494741059608-300x93.png 300w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Index-View-e1494741059608-400x124.png 400w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-12367" class="wp-caption-text">LINQ Basic to Advanced Index View</p></div>
<h4>Normal Select Query With StartWith and Take</h4>
<p>Let&#8217;s have a look at the preceding query.</p>
<p>[csharp]<br />
/// &lt;summary&gt;<br />
        /// Linq query with Select<br />
        /// &lt;/summary&gt;<br />
        /// &lt;returns&gt;&lt;/returns&gt;<br />
        public ActionResult LoadAll()<br />
        {<br />
            var loadAllData = (from d in DtContext.Cities where d.CityName.StartsWith(&quot;C&quot;) select d).Take(10);</p>
<p>            //Method Chain Format<br />
            var loadAllData1 = DtContext.Cities.Where(d =&gt; d.CityName.StartsWith(&quot;C&quot;)).Take(10);</p>
<p>            return PartialView(loadAllData);<br />
        }<br />
[/csharp]</p>
<p>As you can see, we are just fetching the data from Cities in both ways. And we are using StartWith as a filter, which actually looks for the city names which starts with the letter C, and finally we are taking 10 elements from it. The first query is the &#8220;Query syntax&#8221; and the second one is &#8220;Method chain&#8221;. Personally I like the second way. How about you?</p>
<p>[html]<br />
@model IQueryable&lt;LINQ_B_to_A.Models.City&gt;<br />
&lt;style&gt;<br />
    dd, dt, pre {<br />
        border: 1px solid #ccc;<br />
        padding: 5px;<br />
        margin: 5px;<br />
        width: auto;<br />
        width: 20%;<br />
    }</p>
<p>    dd {<br />
        background-color: #a9a9a9<br />
    }<br />
    pre {<br />
        width: auto;<br />
    }<br />
&lt;/style&gt;<br />
&lt;dd&gt;City Names&lt;/dd&gt;<br />
@foreach (var ctyObj in Model)<br />
{<br />
    &lt;dt&gt;@ctyObj.CityName&lt;/dt&gt;<br />
}<br />
&lt;pre&gt;<br />
        public ActionResult LoadAll()<br />
        {<br />
            var loadAllData = (from d in DtContext.Cities where d.CityName.StartsWith(&quot;C&quot;) select d).Take(10);</p>
<p>            //Method Chain Format<br />
            var loadAllData1 = DtContext.Cities.Where(d =&gt; d.CityName.StartsWith(&quot;C&quot;)).Take(10);</p>
<p>            return PartialView(loadAllData);<br />
        }<br />
&lt;/pre&gt;<br />
[/html]</p>
<p>We are ready to see our first query in action now. </p>
<p>Let&#8217;s creat a partial view now to show the data we fetched. <a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Normal-Select-Query-With-StartsWith-and-Take-e1494741383811.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Normal-Select-Query-With-StartsWith-and-Take-e1494741383811.png" alt="LINQ Basic to Advanced Normal Select Query With StartsWith and Take" width="634" height="400" class="alignnone size-full wp-image-12368" srcset="/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Normal-Select-Query-With-StartsWith-and-Take-e1494741383811.png 634w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Normal-Select-Query-With-StartsWith-and-Take-e1494741383811-300x189.png 300w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Normal-Select-Query-With-StartsWith-and-Take-e1494741383811-400x252.png 400w" sizes="(max-width: 634px) 100vw, 634px" /></a></p>
<h4>JOIN Query</h4>
<p>To write a join, the query would be as preceding.</p>
<p>[csharp]<br />
/// &lt;summary&gt;<br />
        /// Linq query with join and where<br />
        /// &lt;/summary&gt;<br />
        /// &lt;returns&gt;&lt;/returns&gt;<br />
        public ActionResult JoinWithWhere()<br />
        {<br />
            var loadAllData = (from oOrders in DtContext.Orders<br />
                               join oOrderLines in DtContext.OrderLines<br />
                               on oOrders.OrderID equals oOrderLines.OrderID<br />
                               orderby oOrders.OrderID<br />
                               select new OrderAndOrderLines()<br />
                               {<br />
                                   OrderId = oOrders.OrderID,<br />
                                   Description = oOrderLines.Description,<br />
                                   Quantity = oOrderLines.Quantity<br />
                               }).Take(10);<br />
            //Method Chain Format<br />
            var asMethodChain = DtContext.Orders.Join(DtContext.OrderLines, oOrders =&gt; oOrders.OrderID,<br />
                    oOrderLines =&gt; oOrderLines.OrderID,<br />
                    (oOrders, oOrderLines) =&gt; new { oOrders, oOrderLines })<br />
                .OrderBy(@o =&gt; @o.oOrders.OrderID)<br />
                .Select(@s =&gt; new OrderAndOrderLines()<br />
                {<br />
                    OrderId = @s.oOrders.OrderID,<br />
                    Description = @s.oOrderLines.Description,<br />
                    Quantity = @s.oOrderLines.Quantity<br />
                }).Take(10);</p>
<p>            return PartialView(loadAllData);<br />
        }<br />
[/csharp]</p>
<p>In the above query we are just joining the tables Order and OrderLines with OrderID and to select we are using an another custom model OrderAndOrderLines. </p>
<p>[csharp]<br />
namespace LINQ_B_to_A.Models<br />
{<br />
    public partial class OrderAndOrderLines<br />
    {<br />
        public int OrderId { get; set; }<br />
        public string Description { get; set; }<br />
        public int? Quantity { get; set; }<br />
    }<br />
}<br />
[/csharp]</p>
<p>The view can be written as follows.</p>
<p>[html]<br />
@model IEnumerable&lt;LINQ_B_to_A.Models.OrderAndOrderLines&gt;<br />
&lt;style&gt;<br />
    td, th, thead,pre {<br />
        border: 1px solid #ccc;<br />
        padding: 5px;<br />
        margin: 5px;<br />
        width: auto;<br />
        width: 20%;<br />
    }</p>
<p>    caption {<br />
        background-color: #a9a9a9<br />
    }<br />
    pre {<br />
        width: auto;<br />
    }<br />
&lt;/style&gt;</p>
<p>&lt;table&gt;<br />
    &lt;caption&gt;Order Details&lt;/caption&gt;<br />
    &lt;tr&gt;<br />
        &lt;th&gt;Order ID&lt;/th&gt;<br />
        &lt;th&gt;Description&lt;/th&gt;<br />
        &lt;th&gt;Quantity&lt;/th&gt;<br />
    &lt;/tr&gt;<br />
    @foreach (var @item in Model)<br />
    {<br />
        &lt;tr&gt;<br />
            &lt;td&gt;@item.OrderId&lt;/td&gt;<br />
            &lt;td&gt;@item.Description&lt;/td&gt;<br />
            &lt;td&gt;@item.Quantity&lt;/td&gt;<br />
        &lt;/tr&gt;<br />
    }<br />
&lt;/table&gt;<br />
&lt;pre&gt;<br />
     public ActionResult JoinWithWhere()<br />
        {<br />
            var loadAllData = (from oOrders in DtContext.Orders<br />
                               join oOrderLines in DtContext.OrderLines<br />
                               on oOrders.OrderID equals oOrderLines.OrderID<br />
                               orderby oOrders.OrderID<br />
                               select new OrderAndOrderLines()<br />
                               {<br />
                                   OrderId = oOrders.OrderID,<br />
                                   Description = oOrderLines.Description,<br />
                                   Quantity = oOrderLines.Quantity<br />
                               }).Take(10);<br />
            //Method Chain Format<br />
            var asMethodChain = DtContext.Orders.Join(DtContext.OrderLines, oOrders =&gt; oOrders.OrderID,<br />
                    oOrderLines =&gt; oOrderLines.OrderID,<br />
                    (oOrders, oOrderLines) =&gt; new { oOrders, oOrderLines })<br />
                .OrderBy(o =&gt; o.oOrders.OrderID)<br />
                .Select(s =&gt; new OrderAndOrderLines()<br />
                {<br />
                    OrderId = s.oOrders.OrderID,<br />
                    Description = s.oOrderLines.Description,<br />
                    Quantity = s.oOrderLines.Quantity<br />
                }).Take(10);</p>
<p>            return PartialView(loadAllData);<br />
        }<br />
&lt;/pre&gt;<br />
[/html]</p>
<p>Once you run the action you can see the result as follows. </p>
<div id="attachment_12369" style="width: 1654px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Join-With-Where-e1494742473978.png"><img decoding="async" aria-describedby="caption-attachment-12369" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Join-With-Where-e1494742473978.png" alt="LINQ Basic to Advanced Join With Where" width="1644" height="821" class="size-full wp-image-12369" srcset="/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Join-With-Where-e1494742473978.png 634w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Join-With-Where-e1494742473978-300x150.png 300w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Join-With-Where-e1494742473978-400x200.png 400w" sizes="(max-width: 1644px) 100vw, 1644px" /></a><p id="caption-attachment-12369" class="wp-caption-text">LINQ Basic to Advanced Join With Where</p></div>
<h4>Left JOIN Query</h4>
<p>To write a Left join, the query would be as preceding.</p>
<p>[csharp]<br />
/// &lt;summary&gt;<br />
        /// Linq query with Left Join<br />
        /// &lt;/summary&gt;<br />
        /// &lt;returns&gt;&lt;/returns&gt;<br />
        public ActionResult LeftJoin()<br />
        {<br />
            var loadAllData = (from oOrder in DtContext.Orders<br />
                               join oOrderLine in DtContext.OrderLines<br />
                               on oOrder.OrderID equals oOrderLine.OrderID<br />
                               into lftOrder<br />
                               from afterJoined in lftOrder.DefaultIfEmpty()<br />
                               orderby oOrder.OrderID descending<br />
                               select new OrderAndOrderLines()<br />
                               {<br />
                                   OrderId = oOrder.OrderID,<br />
                                   Description = afterJoined.Description<br />
                               }).Take(10).ToList();<br />
            //Method Chain Format<br />
            var lftJoinMethodChain = (DtContext.Orders.GroupJoin(DtContext.OrderLines,<br />
                    oOrder =&gt; oOrder.OrderID, oOrderLine =&gt; oOrderLine.OrderID,<br />
                    (oOrder, lftJoin) =&gt; new { oOrder, lftJoin })<br />
                .SelectMany(@sm =&gt; @sm.lftJoin.DefaultIfEmpty(), (@sm, afterJoin) =&gt; new { @sm, afterJoin })<br />
                .OrderByDescending(@o =&gt; @o.sm.oOrder.OrderID)<br />
                .Select(@s =&gt; new OrderAndOrderLines()<br />
                {<br />
                    OrderId = @s.sm.oOrder.OrderID,<br />
                    Description = @s.afterJoin.Description<br />
                })).Take(10).ToList();</p>
<p>            return PartialView(loadAllData);<br />
        }<br />
[/csharp]</p>
<p>In the above query we are just joining the tables Order and OrderLines with OrderID and to select we are using an another custom model OrderAndOrderLines as our previous query. The differences you could find here are, using an &#8216;into&#8217; and &#8216;DefaultIfEmpty&#8217; statements. The DefaultIfEmpty is making sure that it returns empty if there is no appropriate rows found in the second table. </p>
<p>The view can be written as follows.</p>
<p>[html]<br />
@model IEnumerable&lt;LINQ_B_to_A.Models.OrderAndOrderLines&gt;<br />
&lt;style&gt;<br />
    td, th, thead, pre {<br />
        border: 1px solid #ccc;<br />
        padding: 5px;<br />
        margin: 5px;<br />
        width: auto;<br />
        width: 20%;<br />
    }</p>
<p>    caption {<br />
        background-color: #a9a9a9<br />
    }<br />
    pre {<br />
        width: auto;<br />
    }<br />
&lt;/style&gt;</p>
<p>&lt;table&gt;<br />
    &lt;caption&gt;Order Details&lt;/caption&gt;<br />
    &lt;tr&gt;<br />
        &lt;th&gt;Order ID&lt;/th&gt;<br />
        &lt;th&gt;Description&lt;/th&gt;<br />
        &lt;th&gt;Quantity&lt;/th&gt;<br />
    &lt;/tr&gt;<br />
    @foreach (var @item in Model)<br />
    {<br />
        &lt;tr&gt;<br />
            &lt;td&gt;@item.OrderId&lt;/td&gt;<br />
            &lt;td&gt;@item.Description&lt;/td&gt;<br />
            &lt;td&gt;@item.Quantity&lt;/td&gt;<br />
        &lt;/tr&gt;<br />
    }<br />
&lt;/table&gt;<br />
&lt;pre&gt;<br />
    public ActionResult LeftJoin()<br />
        {<br />
            var loadAllData = (from oOrder in DtContext.Orders<br />
                               join oOrderLine in DtContext.OrderLines<br />
                               on oOrder.OrderID equals oOrderLine.OrderID<br />
                               into lftOrder<br />
                               from afterJoined in lftOrder.DefaultIfEmpty()<br />
                               orderby oOrder.OrderID descending<br />
                               select new OrderAndOrderLines()<br />
                               {<br />
                                   OrderId = oOrder.OrderID,<br />
                                   Description = afterJoined.Description<br />
                               }).Take(10).ToList();<br />
            //Method Chain Format<br />
            var lftJoinMethodChain = (DtContext.Orders.GroupJoin(DtContext.OrderLines,<br />
                    oOrder =&gt; oOrder.OrderID, oOrderLine =&gt; oOrderLine.OrderID,<br />
                    (oOrder, lftJoin) =&gt; new { oOrder, lftJoin })<br />
                .SelectMany(sm =&gt; sm.lftJoin.DefaultIfEmpty(), (sm, afterJoin) =&gt; new { sm, afterJoin })<br />
                .OrderByDescending(o =&gt; o.sm.oOrder.OrderID)<br />
                .Select(s =&gt; new OrderAndOrderLines()<br />
                {<br />
                    OrderId = s.sm.oOrder.OrderID,<br />
                    Description = s.afterJoin.Description<br />
                })).Take(10).ToList();</p>
<p>            return PartialView(loadAllData);<br />
        }<br />
&lt;/pre&gt;<br />
[/html]</p>
<p>Once you run the action you can see the result as follows. </p>
<div id="attachment_12370" style="width: 1658px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Left-Join-e1494742942417.png"><img decoding="async" aria-describedby="caption-attachment-12370" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Left-Join-e1494742942417.png" alt="LINQ Basic to Advanced Left Join" width="1648" height="820" class="size-full wp-image-12370" srcset="/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Left-Join-e1494742942417.png 634w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Left-Join-e1494742942417-300x149.png 300w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Left-Join-e1494742942417-400x199.png 400w" sizes="(max-width: 1648px) 100vw, 1648px" /></a><p id="caption-attachment-12370" class="wp-caption-text">LINQ Basic to Advanced Left Join</p></div>
<p>As you can see in the image, the order id 200000 doesn&#8217;t has any appropriate rows in the second table, so it shows as empty.</p>
<h4>Distinct Query</h4>
<p>The below query shows how we can write simple distinct query.</p>
<p>[csharp]<br />
/// &lt;summary&gt;<br />
        /// Linq query Distinct sample<br />
        /// &lt;/summary&gt;<br />
        /// &lt;returns&gt;&lt;/returns&gt;<br />
        public ActionResult DistinctSample()<br />
        {<br />
            var distictSample = (from oOrder in DtContext.OrderLines<br />
                                 select oOrder.Description).Distinct().Take(10).ToList();</p>
<p>            //Method Chain Format<br />
            var distictAsMethodChain = (DtContext.OrderLines.Select(oOrder =&gt; oOrder.Description)).Distinct().Take(10).ToList();</p>
<p>            return PartialView(distictSample);<br />
        }<br />
[/csharp]</p>
<p>In the above query we use Distinct to make sure that only distict items are selected from the result. The view can be written as follows.</p>
<p>[html]<br />
@model  List&lt;string&gt;<br />
&lt;style&gt;<br />
    dd, dt, pre {<br />
        border: 1px solid #ccc;<br />
        padding: 5px;<br />
        margin: 5px;<br />
        width: auto;<br />
        width: 20%;<br />
    }</p>
<p>    dd {<br />
        background-color: #a9a9a9<br />
    }</p>
<p>    pre {<br />
        width: auto;<br />
    }<br />
&lt;/style&gt;<br />
&lt;dd&gt;Order Descriptions&lt;/dd&gt;<br />
@foreach (var orderLinesyObj in Model)<br />
{<br />
    &lt;dt&gt;@orderLinesyObj&lt;/dt&gt;<br />
}<br />
&lt;pre&gt;<br />
    public ActionResult DistinctSample()<br />
        {<br />
            var distictSample = (from oOrder in DtContext.OrderLines<br />
                                 select oOrder.Description).Distinct().Take(10).ToList();</p>
<p>            //Method Chain Format<br />
            var distictAsMethodChain = (DtContext.OrderLines.Select(oOrder =&gt; oOrder.Description)).Distinct().Take(10).ToList();</p>
<p>            return PartialView(distictSample);<br />
        }<br />
&lt;/pre&gt;<br />
[/html]</p>
<p>Once you run the action you can see the result as follows.</p>
<div id="attachment_12371" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Distinct-Query-e1494743542508.png"><img decoding="async" aria-describedby="caption-attachment-12371" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Distinct-Query-e1494743542508.png" alt="LINQ Basic to Advanced Distinct Query" width="634" height="372" class="size-full wp-image-12371" srcset="/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Distinct-Query-e1494743542508.png 634w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Distinct-Query-e1494743542508-300x176.png 300w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Distinct-Query-e1494743542508-400x235.png 400w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-12371" class="wp-caption-text">LINQ Basic to Advanced Distinct Query</p></div>
<h4>Equals and Not Equals Queries</h4>
<p>We can write the equals and not equals query as preceding.</p>
<p>[csharp]<br />
/// &lt;summary&gt;<br />
        /// Linq query Equals sample<br />
        /// &lt;/summary&gt;<br />
        /// &lt;returns&gt;&lt;/returns&gt;<br />
        public ActionResult EqualsSamples()<br />
        {<br />
            var objEquals = (from objCity in DtContext.Cities<br />
                             where objCity.CityName.Equals(&quot;Troy&quot;)<br />
                             select objCity).Take(2);<br />
            //Method Chain Format<br />
            var objEquals1 = DtContext.Cities.Where(d =&gt; d.CityName.Equals(&quot;Troy&quot;)).Take(2);</p>
<p>            return PartialView(&quot;OperatorSamples&quot;, objEquals);<br />
        }</p>
<p>        /// &lt;summary&gt;<br />
        /// Linq query Not Equals sample<br />
        /// &lt;/summary&gt;<br />
        /// &lt;returns&gt;&lt;/returns&gt;<br />
        public ActionResult NotEqualsSamples()<br />
        {<br />
            var objNotEquals = (from objCity in DtContext.Cities<br />
                                where objCity.CityName != &quot;Troy&quot;<br />
                                select objCity).Take(5);</p>
<p>            var objNotEquals1 = (from objCity in DtContext.Cities<br />
                                 where !objCity.CityName.Equals(&quot;Troy&quot;)<br />
                                 select objCity).Take(5);</p>
<p>            //Method Chain Format<br />
            var objNotEquals2 = DtContext.Cities.Where(d =&gt; d.CityName != &quot;Troy&quot;).Take(2);</p>
<p>            var objNotEquals3 = DtContext.Cities.Where(d =&gt; !d.CityName.Equals(&quot;Troy&quot;)).Take(2);</p>
<p>            return PartialView(&quot;OperatorSamples&quot;, objNotEquals);<br />
        }<br />
[/csharp]</p>
<p>The view can be written as follows.</p>
<p>[html]<br />
@model IQueryable&lt;LINQ_B_to_A.Models.City&gt;<br />
&lt;style&gt;<br />
    td, th, thead, pre {<br />
        border: 1px solid #ccc;<br />
        padding: 5px;<br />
        margin: 5px;<br />
        width: auto;<br />
        width: 20%;<br />
    }</p>
<p>    caption {<br />
        background-color: #a9a9a9<br />
    }</p>
<p>    pre {<br />
        width: auto;<br />
    }<br />
&lt;/style&gt;</p>
<p>    &lt;table&gt;<br />
        &lt;caption&gt;City Details&lt;/caption&gt;<br />
        &lt;tr&gt;<br />
            &lt;th&gt;City ID&lt;/th&gt;<br />
            &lt;th&gt;City Name&lt;/th&gt;<br />
            &lt;th&gt;City Location&lt;/th&gt;<br />
        &lt;/tr&gt;<br />
@foreach (var @item in Model)<br />
{<br />
    &lt;tr&gt;<br />
    &lt;td&gt;@item.CityID&lt;/td&gt;<br />
    &lt;td&gt;@item.CityName&lt;/td&gt;<br />
    &lt;td&gt;@item.Location&lt;/td&gt;<br />
    &lt;/tr&gt;<br />
}<br />
    &lt;/table&gt;<br />
&lt;caption&gt;Equals Oerator&lt;/caption&gt;<br />
&lt;pre&gt;<br />
    public ActionResult EqualsSamples()<br />
        {<br />
            var objEquals = (from objCity in DtContext.Cities<br />
                                       where objCity.CityName.Equals(&quot;Troy&quot;)<br />
                                       select objCity).Take(2);<br />
            //Method Chain Format<br />
            var objEquals1 = DtContext.Cities.Where(d =&gt; d.CityName.Equals(&quot;Troy&quot;)).Take(2);</p>
<p>            return PartialView(&quot;OperatorSamples&quot;, objEquals);<br />
        }</p>
<p>        public ActionResult NotEqualsSamples()<br />
        {<br />
            var objNotEquals = (from objCity in DtContext.Cities<br />
                where objCity.CityName != &quot;Troy&quot;<br />
                select objCity).Take(5);</p>
<p>            var objNotEquals1 = (from objCity in DtContext.Cities<br />
                where !objCity.CityName.Equals(&quot;Troy&quot;)<br />
                select objCity).Take(5);</p>
<p>            //Method Chain Format<br />
            var objNotEquals2 = DtContext.Cities.Where(d =&gt; d.CityName != &quot;Troy&quot;).Take(2);</p>
<p>            var objNotEquals3 = DtContext.Cities.Where(d =&gt; !d.CityName.Equals(&quot;Troy&quot;)).Take(2);</p>
<p>            return PartialView(&quot;OperatorSamples&quot;, objNotEquals);<br />
        }</p>
<p>        public ActionResult PagingQueries()<br />
        {<br />
            var objNotEquals = (from objCity in DtContext.Cities<br />
                where objCity.CityName != &quot;Troy&quot;<br />
                orderby objCity.CityName ascending<br />
                select objCity).Skip(5).Take(5);</p>
<p>            //Method Chain Format<br />
            var objNotEquals2 = DtContext.Cities.Where(d =&gt; d.CityName != &quot;Troy&quot;).Skip(5).Take(5);</p>
<p>            return PartialView(&quot;OperatorSamples&quot;, objNotEquals);<br />
        }<br />
&lt;/pre&gt;<br />
[/html]</p>
<p>Once you run the action you can see the result as follows.</p>
<div id="attachment_12372" style="width: 1622px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Equals-and-Not-Equals-e1494744042305.png"><img decoding="async" aria-describedby="caption-attachment-12372" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Equals-and-Not-Equals-e1494744042305.png" alt="LINQ Basic to Advanced Equals and Not Equals" width="1612" height="560" class="size-full wp-image-12372" srcset="/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Equals-and-Not-Equals-e1494744042305.png 634w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Equals-and-Not-Equals-e1494744042305-300x104.png 300w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Equals-and-Not-Equals-e1494744042305-400x139.png 400w" sizes="(max-width: 1612px) 100vw, 1612px" /></a><p id="caption-attachment-12372" class="wp-caption-text">LINQ Basic to Advanced Equals and Not Equals</p></div>
<h4>LINQ Paging Queries</h4>
<p>Paging queries are always important as we work in some grid controls, with LINQ those are very easy. Let&#8217;s see one of that query. </p>
<p>[csharp]<br />
/// &lt;summary&gt;<br />
        /// Linq Paging Queries<br />
        /// &lt;/summary&gt;<br />
        /// &lt;returns&gt;&lt;/returns&gt;<br />
        public ActionResult PagingQueries()<br />
        {<br />
            var objNotEquals = (from objCity in DtContext.Cities<br />
                                where objCity.CityName != &quot;Troy&quot;<br />
                                orderby objCity.CityName ascending<br />
                                select objCity).Skip(5).Take(5);</p>
<p>            //Method Chain Format<br />
            var objNotEquals2 = DtContext.Cities.Where(d =&gt; d.CityName != &quot;Troy&quot;).Skip(5).Take(5);</p>
<p>            return PartialView(&quot;OperatorSamples&quot;, objNotEquals);<br />
        }<br />
[/csharp]</p>
<p>Once you run the action you can see the result as follows.</p>
<div id="attachment_12373" style="width: 1611px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Paging-Queries-e1494744396637.png"><img decoding="async" aria-describedby="caption-attachment-12373" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Paging-Queries-e1494744396637.png" alt="LINQ Basic to Advanced Paging Queries" width="1601" height="862" class="size-full wp-image-12373" srcset="/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Paging-Queries-e1494744396637.png 634w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Paging-Queries-e1494744396637-300x161.png 300w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Paging-Queries-e1494744396637-400x215.png 400w" sizes="(max-width: 1601px) 100vw, 1601px" /></a><p id="caption-attachment-12373" class="wp-caption-text">LINQ Basic to Advanced Paging Queries</p></div>
<h4>LINQ Math Queries</h4>
<p>Here we are going to write the possible Math functions in our LINQ query.</p>
<p>[csharp]<br />
/// &lt;summary&gt;<br />
        /// Math Queries<br />
        /// &lt;/summary&gt;<br />
        /// &lt;returns&gt;&lt;/returns&gt;<br />
        public ActionResult MathQueries()<br />
        {<br />
            var objMath = (from objInv in DtContext.InvoiceLines<br />
                           where objInv.ExtendedPrice &gt; 10 &amp;&amp; objInv.Quantity &lt; 15<br />
                           orderby objInv.InvoiceLineID descending<br />
                           select new MathClass()<br />
                           {<br />
                               Actual = objInv.ExtendedPrice,<br />
                               Round = Math.Round(objInv.ExtendedPrice),<br />
                               Floor = Math.Floor(objInv.ExtendedPrice),<br />
                               Ceiling = Math.Ceiling(objInv.ExtendedPrice),<br />
                               Abs = Math.Abs(objInv.ExtendedPrice)<br />
                           }).Take(10);</p>
<p>            //Method Chain Format<br />
            var objMath2 = DtContext.InvoiceLines<br />
                .Where(objInv =&gt; objInv.ExtendedPrice &gt; 10 &amp;&amp; objInv.Quantity &lt; 15)<br />
                .OrderByDescending(o =&gt; o.InvoiceLineID)<br />
                .Select(objInv =&gt; new MathClass()<br />
                {<br />
                    Actual = objInv.ExtendedPrice,<br />
                    Round = Math.Round(objInv.ExtendedPrice),<br />
                    Floor = Math.Floor(objInv.ExtendedPrice),<br />
                    Ceiling = Math.Ceiling(objInv.ExtendedPrice),<br />
                    Abs = Math.Abs(objInv.ExtendedPrice)<br />
                }).Take(10);</p>
<p>            return PartialView(&quot;MathQueries&quot;, objMath);<br />
        }<br />
[/csharp]</p>
<p>As you can see we have written most of the possible Math functions in our query and selecting with a custome model MathClass.</p>
<p>[csharp]<br />
namespace LINQ_B_to_A.Models<br />
{<br />
    public partial class MathClass<br />
    {<br />
        public decimal Actual { get; set; }<br />
        public decimal Round { get; set; }<br />
        public decimal Floor { get; set; }<br />
        public decimal Ceiling { get; set; }<br />
        public decimal Abs { get; set; }<br />
    }<br />
}<br />
[/csharp]</p>
<p>Let&#8217;s see the view now. </p>
<p>[html]</p>
<p>@model IQueryable&lt;LINQ_B_to_A.Models.MathClass&gt;<br />
&lt;style&gt;<br />
    td, th, thead, pre {<br />
        border: 1px solid #ccc;<br />
        padding: 5px;<br />
        margin: 5px;<br />
        width: auto;<br />
        width: 20%;<br />
    }</p>
<p>    caption {<br />
        background-color: #a9a9a9<br />
    }</p>
<p>    pre {<br />
        width: auto;<br />
    }<br />
&lt;/style&gt;</p>
<p>&lt;table&gt;<br />
    &lt;caption&gt;Math Operators&lt;/caption&gt;<br />
    &lt;tr&gt;</p>
<p>    &lt;/tr&gt;<br />
    @foreach (var @item in Model)<br />
    {<br />
        &lt;tr&gt;<br />
            &lt;td&gt;Actual: @item.Actual&lt;/td&gt;<br />
            &lt;td&gt;Round: @item.Round&lt;/td&gt;<br />
            &lt;td&gt;Floor: @item.Floor&lt;/td&gt;<br />
            &lt;td&gt;Ceiling: @item.Ceiling&lt;/td&gt;<br />
            &lt;td&gt;Abs: @item.Abs&lt;/td&gt;<br />
        &lt;/tr&gt;<br />
    }<br />
&lt;/table&gt;<br />
&lt;pre&gt;<br />
    public ActionResult MathQueries()<br />
        {<br />
            var objMath = (from objInv in DtContext.InvoiceLines<br />
                          where objInv.ExtendedPrice &gt; 10 &amp;&amp; objInv.Quantity &lt; 15<br />
                          orderby objInv.InvoiceLineID descending<br />
                          select new MathClass()<br />
                          {<br />
                              Actual = objInv.ExtendedPrice,<br />
                              Round = Math.Round(objInv.ExtendedPrice),<br />
                              Floor = Math.Floor(objInv.ExtendedPrice),<br />
                              Ceiling = Math.Ceiling(objInv.ExtendedPrice),<br />
                              Abs = Math.Abs(objInv.ExtendedPrice)<br />
                          }).Take(10);</p>
<p>            //Method Chain Format<br />
            var objMath2 = DtContext.InvoiceLines<br />
                .Where(objInv =&gt; objInv.ExtendedPrice &gt; 10 &amp;&amp; objInv.Quantity &lt; 15)<br />
                .OrderByDescending(o =&gt; o.InvoiceLineID)<br />
                .Select(objInv =&gt; new MathClass()<br />
                {<br />
                    Actual = objInv.ExtendedPrice,<br />
                    Round = Math.Round(objInv.ExtendedPrice),<br />
                    Floor = Math.Floor(objInv.ExtendedPrice),<br />
                    Ceiling = Math.Ceiling(objInv.ExtendedPrice),<br />
                    Abs = Math.Abs(objInv.ExtendedPrice)<br />
                }).Take(10);</p>
<p>            return PartialView(&quot;MathQueries&quot;, objMath);<br />
        }<br />
&lt;/pre&gt;<br />
[/html]</p>
<p>See the result now.</p>
<div id="attachment_12374" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Math-Queries-e1494744783496.png"><img decoding="async" aria-describedby="caption-attachment-12374" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Math-Queries-e1494744783496.png" alt="LINQ Basic to Advanced Math Queries" width="634" height="673" class="size-full wp-image-12374" srcset="/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Math-Queries-e1494744783496.png 336w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Math-Queries-e1494744783496-283x300.png 283w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Math-Queries-e1494744783496-400x425.png 400w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Math-Queries-e1494744783496-565x600.png 565w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-12374" class="wp-caption-text">LINQ Basic to Advanced Math Queries</p></div>
<h4>LINQ String Queries</h4>
<p>As we saw the Math queries, here we are going to write the possible String functions in our LINQ query.</p>
<p>[csharp]<br />
/// &lt;summary&gt;<br />
        /// String Queries<br />
        /// &lt;/summary&gt;<br />
        /// &lt;returns&gt;&lt;/returns&gt;<br />
        public ActionResult StringQueries()<br />
        {<br />
            var objString = (from objInv in DtContext.InvoiceLines<br />
                             where objInv.ExtendedPrice &gt; 10 &amp;&amp; objInv.Quantity &lt; 15<br />
                             orderby objInv.InvoiceLineID descending<br />
                             select new StringClass()<br />
                             {<br />
                                 Actual = objInv.Description,<br />
                                 Insert = objInv.Description.Insert(2, &quot;sibeeshpassion&quot;),<br />
                                 Remove = objInv.Description.Remove(1, 1),<br />
                                 Substring = objInv.Description.Substring(2, 3),<br />
                                 ToLower = objInv.Description.ToLower(),<br />
                                 ToUpper = objInv.Description.ToUpper(),<br />
                                 TrimEnd = objInv.Description.TrimEnd(),<br />
                                 TrimStart = objInv.Description.TrimStart()<br />
                             }).Take(2);</p>
<p>            //Method Chain Format<br />
            var objString2 = DtContext.InvoiceLines<br />
                .Where(objInv =&gt; objInv.ExtendedPrice &gt; 10 &amp;&amp; objInv.Quantity &lt; 15)<br />
                .OrderByDescending(o =&gt; o.InvoiceLineID)<br />
                .Select(objInv =&gt; new StringClass()<br />
                {<br />
                    Actual = objInv.Description,<br />
                    Insert = objInv.Description.Insert(2, &quot;sibeeshpassion&quot;),<br />
                    Remove = objInv.Description.Remove(1, 1),<br />
                    Substring = objInv.Description.Substring(2, 3),<br />
                    ToLower = objInv.Description.ToLower(),<br />
                    ToUpper = objInv.Description.ToUpper(),<br />
                    TrimEnd = objInv.Description.TrimEnd(),<br />
                    TrimStart = objInv.Description.TrimStart()<br />
                }).Take(2);</p>
<p>            return PartialView(&quot;StringQueries&quot;, objString);<br />
        }<br />
[/csharp]</p>
<p>As you can see, here we are using a custom model StringClass.</p>
<p>[csharp]<br />
namespace LINQ_B_to_A.Models<br />
{<br />
    public partial class StringClass<br />
    {<br />
        public string Actual { get; set; }<br />
        public string Insert { get; set; }<br />
        public string Remove { get; set; }<br />
        public string Substring { get; set; }<br />
        public string ToUpper { get; set; }<br />
        public string ToLower { get; set; }<br />
        public string TrimStart { get; set; }<br />
        public string TrimEnd { get; set; }<br />
    }<br />
}<br />
[/csharp]</p>
<p>Let&#8217;s see the view now. </p>
<p>[html]</p>
<p>@model IQueryable&lt;LINQ_B_to_A.Models.StringClass&gt;<br />
&lt;style&gt;<br />
    td, th, thead, pre {<br />
        border: 1px solid #ccc;<br />
        padding: 5px;<br />
        margin: 5px;<br />
        width: auto;<br />
        width: 20%;<br />
    }</p>
<p>    caption {<br />
        background-color: #a9a9a9<br />
    }</p>
<p>    pre {<br />
        width: auto;<br />
    }<br />
&lt;/style&gt;</p>
<p>&lt;table&gt;<br />
    &lt;caption&gt;String Operators&lt;/caption&gt;<br />
    &lt;tr&gt;</p>
<p>    &lt;/tr&gt;<br />
    @foreach (var @item in Model)<br />
    {<br />
        &lt;tr&gt;<br />
            &lt;td&gt;Actual: @item.Actual&lt;/td&gt;<br />
            &lt;td&gt;Insert: @item.Insert&lt;/td&gt;<br />
            &lt;td&gt;Remove: @item.Remove&lt;/td&gt;<br />
            &lt;td&gt;Substring: @item.Substring&lt;/td&gt;<br />
            &lt;td&gt;ToLower: @item.ToLower&lt;/td&gt;<br />
            &lt;td&gt;ToUpper: @item.ToUpper&lt;/td&gt;<br />
            &lt;td&gt;TrimEnd: @item.TrimEnd&lt;/td&gt;<br />
            &lt;td&gt;TrimStart: @item.TrimStart&lt;/td&gt;<br />
        &lt;/tr&gt;<br />
    }<br />
&lt;/table&gt;<br />
&lt;pre&gt;<br />
        public ActionResult StringQueries()<br />
        {<br />
            var objString = (from objInv in DtContext.InvoiceLines<br />
                where objInv.ExtendedPrice &gt; 10 &amp;&amp; objInv.Quantity &lt; 15<br />
                orderby objInv.InvoiceLineID descending<br />
                select new StringClass()<br />
                {</p>
<p>                    Actual = objInv.Description,<br />
                    Insert = objInv.Description.Insert(2,&quot;sibeeshpassion&quot;),<br />
                    Remove = objInv.Description.Remove(1,1),<br />
                    Substring = objInv.Description.Substring(2,3),<br />
                    ToLower = objInv.Description.ToLower(),<br />
                    ToUpper = objInv.Description.ToUpper(),<br />
                    TrimEnd = objInv.Description.TrimEnd(),<br />
                    TrimStart = objInv.Description.TrimStart()<br />
                }).Take(2);</p>
<p>            //Method Chain Format<br />
            var objString2 = DtContext.InvoiceLines<br />
                .Where(objInv =&gt; objInv.ExtendedPrice &gt; 10 &amp;&amp; objInv.Quantity &lt; 15)<br />
                .OrderByDescending(o =&gt; o.InvoiceLineID)<br />
                .Select(objInv =&gt; new StringClass()<br />
                {<br />
                    Actual = objInv.Description,<br />
                    Insert = objInv.Description.Insert(2, &quot;sibeeshpassion&quot;),<br />
                    Remove = objInv.Description.Remove(1, 1),<br />
                    Substring = objInv.Description.Substring(2, 3),<br />
                    ToLower = objInv.Description.ToLower(),<br />
                    ToUpper = objInv.Description.ToUpper(),<br />
                    TrimEnd = objInv.Description.TrimEnd(),<br />
                    TrimStart = objInv.Description.TrimStart()<br />
                }).Take(2);</p>
<p>            return PartialView(&quot;StringQueries&quot;, objString);<br />
        }<br />
&lt;/pre&gt;<br />
[/html]</p>
<p>Now see the result.</p>
<div id="attachment_12375" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-String-Queries-e1494745369956.png"><img decoding="async" aria-describedby="caption-attachment-12375" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-String-Queries-e1494745369956.png" alt="LINQ Basic to Advanced String Queries" width="634" height="300" class="size-full wp-image-12375" srcset="/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-String-Queries-e1494745369956.png 634w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-String-Queries-e1494745369956-300x142.png 300w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-String-Queries-e1494745369956-400x189.png 400w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-12375" class="wp-caption-text">LINQ Basic to Advanced String Queries</p></div>
<h4>SelectMany Query</h4>
<p>A SelectMany query flattern the result to a single dimentional collection, so to loop through the result we just need only one loop. </p>
<div id="attachment_12377" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-SelectMany-Tooltip-e1494746794913.png"><img decoding="async" aria-describedby="caption-attachment-12377" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-SelectMany-Tooltip-e1494746794913.png" alt="LINQ Basic to Advanced SelectMany Tooltip" width="634" height="104" class="size-full wp-image-12377" srcset="/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-SelectMany-Tooltip-e1494746794913.png 634w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-SelectMany-Tooltip-e1494746794913-300x49.png 300w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-SelectMany-Tooltip-e1494746794913-400x66.png 400w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-12377" class="wp-caption-text">LINQ Basic to Advanced SelectMany Tooltip</p></div>
<p>If you use the normal Select, you will be getting a list of lists, thus you will have to use two loops to get the datas.</p>
<div id="attachment_12378" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Select-Tooltip-e1494746906690.png"><img decoding="async" aria-describedby="caption-attachment-12378" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Select-Tooltip-e1494746906690.png" alt="LINQ Basic to Advanced Select Tooltip" width="634" height="83" class="size-full wp-image-12378" srcset="/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Select-Tooltip-e1494746906690.png 634w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Select-Tooltip-e1494746906690-300x39.png 300w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-Select-Tooltip-e1494746906690-400x52.png 400w" sizes="(max-width: 634px) 100vw, 634px" /></a><p id="caption-attachment-12378" class="wp-caption-text">LINQ Basic to Advanced Select Tooltip</p></div>
<p>[csharp]<br />
 /// &lt;summary&gt;<br />
        /// Linq query with SelectMany<br />
        /// &lt;/summary&gt;<br />
        /// &lt;returns&gt;&lt;/returns&gt;<br />
        public ActionResult SelectMany()<br />
        {<br />
            var selectMany = DtContext.Orders.SelectMany(order =&gt; order.Invoices).Take(10);<br />
            var select = DtContext.Orders.Select(order =&gt; order.Invoices).Take(10);<br />
            return PartialView(&quot;SelectMany&quot;, selectMany);<br />
        }<br />
[/csharp]</p>
<p>Let&#8217;s see the view now. </p>
<p>[html]<br />
@model IQueryable&lt;LINQ_B_to_A.Models.Invoice&gt;<br />
&lt;style&gt;<br />
    td, th, thead, pre {<br />
        border: 1px solid #ccc;<br />
        padding: 5px;<br />
        margin: 5px;<br />
        width: auto;<br />
        width: 20%;<br />
    }</p>
<p>    caption {<br />
        background-color: #a9a9a9<br />
    }</p>
<p>    pre {<br />
        width: auto;<br />
    }<br />
&lt;/style&gt;</p>
<p>&lt;table&gt;<br />
    &lt;caption&gt;Invoice Details&lt;/caption&gt;<br />
    &lt;tr&gt;<br />
        &lt;th&gt;Order ID&lt;/th&gt;<br />
        &lt;th&gt;Invoice ID&lt;/th&gt;<br />
        &lt;th&gt;Invoice Date&lt;/th&gt;<br />
    &lt;/tr&gt;<br />
    @foreach (var @item in Model)<br />
    {<br />
        &lt;tr&gt;<br />
            &lt;td&gt;@item.OrderID&lt;/td&gt;<br />
            &lt;td&gt;@item.InvoiceID&lt;/td&gt;<br />
            &lt;td&gt;@item.InvoiceDate&lt;/td&gt;<br />
        &lt;/tr&gt;<br />
    }<br />
&lt;/table&gt;<br />
&lt;caption&gt;Select Many&lt;/caption&gt;<br />
&lt;pre&gt;<br />
     /// &lt;summary&gt;<br />
        /// Linq query with SelectMany<br />
        /// &lt;/summary&gt;<br />
        /// &lt;returns&gt;&lt;/returns&gt;<br />
        public ActionResult SelectMany()<br />
        {<br />
            var selectMany = DtContext.Orders.SelectMany(order =&gt; order.Invoices).Take(10);<br />
            var select = DtContext.Orders.Select(order =&gt; order.Invoices).Take(10);<br />
            return PartialView(&quot;SelectMany&quot;, selectMany);<br />
        }<br />
&lt;/pre&gt;<br />
[/html]</p>
<p>Now see the result.</p>
<p>That&#8217;s all for today, I will come with another set of LINQ queries in the next part. Till then, bye.</p>
<div id="attachment_12379" style="width: 952px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-SelectMany-e1494747140197.png"><img decoding="async" aria-describedby="caption-attachment-12379" src="http://sibeeshpassion.com/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-SelectMany-e1494747140197.png" alt="LINQ Basic to Advanced SelectMany" width="942" height="597" class="size-full wp-image-12379" srcset="/wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-SelectMany-e1494747140197.png 634w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-SelectMany-e1494747140197-300x190.png 300w, /wp-content/uploads/2017/05/LINQ-Basic-to-Advanced-SelectMany-e1494747140197-400x254.png 400w" sizes="(max-width: 942px) 100vw, 942px" /></a><p id="caption-attachment-12379" class="wp-caption-text">LINQ Basic to Advanced SelectMany</p></div>
<h3>Conclusion</h3>
<p>Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<h3>Your turn. What do you think?</h3>
<p>A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/linq-basic-to-advanced-mvc-demo-application/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>C sharp Interview Questions And Answers</title>
		<link>https://sibeeshpassion.com/c-sharp-interview-questions-and-answers/</link>
					<comments>https://sibeeshpassion.com/c-sharp-interview-questions-and-answers/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Sat, 24 Oct 2015 08:06:18 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Interview]]></category>
		<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[C sharp Interview Questions And Answers]]></category>
		<category><![CDATA[Career Advice]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Interview Questions For Dot Net]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=10839</guid>

					<description><![CDATA[[toc] Introduction In this article, we will discuss the most asked C# interview questions and answers. If you need to know other interview questions and answers, I strongly recommend to follow this link: Interview Questions. Now in this post, we are going to share the interview questions for C# or a Dot Net developer. No matter you are experienced or fresher, it is important that you must aware of these. So please read it carefully. I hope you will like this article. Background C# is one of my favorite programming languages. So I am really happy to share you some [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>[toc]</p>



<h2 class="wp-block-heading">Introduction</h2>



<p>In this article, we will discuss the most asked C# interview questions and answers. If you need to know other interview questions and answers, I strongly recommend to follow this link: <a href="http://sibeeshpassion.com/category/interview/" target="_blank" rel="noopener noreferrer">Interview Questions</a>. Now in this post, we are going to share the interview questions for C# or a Dot Net developer. No matter you are experienced or fresher, it is important that you must aware of these. So please read it carefully. I hope you will like this article.</p>



<h2 class="wp-block-heading">Background</h2>



<p>C# is one of my favorite programming languages. So I am really happy to share you some interview questions related to C#. You can always read my other interview questions here in the below links.</p>



<ul class="wp-block-list"><li><a rel="noopener noreferrer" href="http://sibeeshpassion.com/dot-net-interview-questions-for-experienced-and-fresher/" target="_blank">Interview Questions For Experienced and Beginner .NET Professionals</a></li><li><a rel="noopener noreferrer" href="http://sibeeshpassion.com/infosys-interview-questions-for-dotnet-professionals/" target="_blank">Infosys Interview Questions For DotNet Professionals</a></li><li><a rel="noopener noreferrer" href="http://sibeeshpassion.com/sql-interview-questions-and-answers/" target="_blank">SQL Interview Questions And Answers</a></li><li><a rel="noopener noreferrer" href="http://sibeeshpassion.com/important-ado-net-interview-questions/" target="_blank">Important ADO.NET Interview Questions</a> <p>So shall we now discuss C# interview questions? </p></li></ul>



<h3 class="wp-block-heading">C# Interview Questions   </h3>



<p>What are Abstract Classes? </p>



<p>The purpose of an abstract class is to define some common behavior that can be inherited by multiple sub classes, without implementing the entire class. In C#, the abstract keyword designates both an abstract class and a pure virtual method. The purpose of an abstract class is to provide a common definition of a base class that multiple derived classes can share. For example, a class library may define an abstract class that is used as a parameter to many of its functions and require programmers using that library to provide their own implementation of the class by creating a derived class. </p>



<h4 class="wp-block-heading">Properties </h4>



<ul class="wp-block-list"><li>An abstract class cannot be instantiated.</li><li>It can be inherited.</li><li>It can have method implementations, class members.</li><li>Only abstract classes can have abstract methods.</li></ul>



<h4 class="wp-block-heading">Syntax</h4>



<script src="https://gist.github.com/SibeeshVenu/2fa66bd9f38b408fe13317d502e08dc1.js"></script>



<h4 class="wp-block-heading">What are Abstract methods?Give an example?</h4>



<h5 class="wp-block-heading">Abstract Methods</h5>



<p>Abstract methods have no implementation, so the method definition is followed by a semicolon instead of a normal method block. (See above example for syntax)</p>



<p>Derived classes of the abstract class must implement all abstract methods.<br>When an abstract class inherits a virtual method from a base class, the abstract class can override the virtual method with an abstract method.</p>



<h5 class="wp-block-heading">Example</h5>



<script src="https://gist.github.com/SibeeshVenu/08fb0fe1e57b4c9d8cd46d0caf2bfbe9.js"></script>



<script src="https://gist.github.com/SibeeshVenu/a597cb326601e52f65758c6cffd0047b.js"></script>



<h4 class="wp-block-heading">What is Interface? Explain with an example?</h4>



<p>An interface is useful when you want to be able to use some common functionality of otherwise unrelated classes- they share no implementation details, only the function signatures. In C#, function declarations within an interface are implicitly pure virtual.</p>



<p>An interface contains only the signatures of methods, properties, events or indexers. A class or struct that implements the interface must implement the members of the interface that are specified in the interface definition.</p>



<h5 class="wp-block-heading">Properties</h5>



<p>An interface can be a member of a namespace or a class and can contain signatures of methods, properties, events, indexers.<br>An interface can inherit from one or more base interfaces. A class that implements an interface can explicitly implement members of that interface. An explicitly implemented member cannot be accessed through a class instance, but only through an instance of the interface.</p>



<p><strong>Example</strong><em> </em></p>



<script src="https://gist.github.com/SibeeshVenu/3057b3fcb14f7455c4b039b217876398.js"></script>



<script src="https://gist.github.com/SibeeshVenu/d1815c018ef376231553005f421b0949.js"></script>



<script src="https://gist.github.com/SibeeshVenu/a710e1206ab1aaff58263d1b299c7b7e.js"></script>



<p><em><strong>Calling the metho</strong></em><strong>ds </strong></p>



<script src="https://gist.github.com/SibeeshVenu/e54d38f6d8751c9cf06252657197ab78.js"></script>



<script src="https://gist.github.com/SibeeshVenu/8cec8789031f25287a997b150a7fb6cf.js"></script>



<script src="https://gist.github.com/SibeeshVenu/a415a854c7cb4de11e625650a039327b.js"></script>



<h4 class="wp-block-heading">Explain The Difference Between Abstract Class and Interface ?</h4>



<p>An Abstract class doesn&#8217;t provide full abstraction but an interface does provide full abstraction; i.e. both a declaration and a definition is given in an abstract class but not so in an interface. Using Abstract we cannot achieve multiple inheritances but be using an Interface we can achieve multiple inheritances. We cannot declare a member field in an Interface. We cannot use any access modifier i.e. public, private, protected, internal etc. because within an interface by default everything is public. An Interface member cannot be defined using the keyword static, virtual, abstract or sealed.</p>



<h4 class="wp-block-heading">Explain Generic Collections &amp; Array Lists ?</h4>



<p>Generics allow you to delay the specification of the data type of programming elements in a class or a method until it is actually used in the program. In other words, generics allow you to write a class or method that can work with any data type. Generic Collections helps us to create flexible type-safe, strong type collections at compile time.</p>



<h5 class="wp-block-heading">Syntax</h5>



<script src="https://gist.github.com/SibeeshVenu/12e01a38f7fe93800ed2d9e28af1d248.js"></script>



<h5 class="wp-block-heading">Namespace</h5>



<script src="https://gist.github.com/SibeeshVenu/0f0b6f01abc509c5a0c1ed44aecb95c2.js"></script>



<h5 class="wp-block-heading">ArrayList</h5>



<p>They are ordered a collection of objects, that can be resized automatically, that has dynamic memory allocation and which can contain different types of data. Arraylist stores its members as objects, so in order to retrieve it, we must type cast it.</p>



<h5 class="wp-block-heading">Syntax and Example</h5>



<script src="https://gist.github.com/SibeeshVenu/8533989c2ec614777133e892986e18ae.js"></script>



<h5 class="wp-block-heading">Namespace</h5>



<script src="https://gist.github.com/SibeeshVenu/8f232eefceb895791b4a5fa193d499f2.js"></script>



<h4 class="wp-block-heading">What are Finalize and Dispose? Can you list down the differences between them?</h4>



<p>Finalizers are run by the Garbage Collection before an object that is eligible for collection is reclaimed. Dispose() is meant for cleaning up unmanaged resources, like network connections, files, handles to OS stuff, &amp;c. It works best in conjunction with the using block where the compiler makes sure that Dispose() will be called immediately once you are done with an object – and also ensures that you cannot work with the object anymore once it&#8217;s disposed of.</p>



<h5 class="wp-block-heading">Dispose() Method</h5>



<ul class="wp-block-list"><li>This dispose method will be used to free unmanaged resources like files, database connection etc.</li><li>To clear unmanaged resources, we need to write code manually to raise dispose() method.</li><li>This Dispose() method belongs to the IDisposable interface.</li><li>If we need to implement this method for any custom classes we need to inherit the class from IDisposable interface.</li><li>It will not show any effect on the performance of the website and we can use this method whenever we want to free objects immediately.</li></ul>



<h5 class="wp-block-heading">Finalize() Method</h5>



<ul class="wp-block-list"><li>This method also free unmanaged resources like database connections, files etc…</li><li>It is automatically raised by garbage collection mechanism whenever the object goes out of scope.</li><li>This method belongs to object class.</li><li>We need to implement this method whenever we have unmanaged resources in our code and make sure these resources will be freed when garbage collection process was done.</li><li>It will show the effect on the performance of the website and it will not suitable to free objects immediately.</li></ul>



<h4 class="wp-block-heading">What is Dependency Injection?How can we implement it?</h4>



<p>Simply put Dependency injection is for decoupling two components. It can be explained by a simple example.</p>



<script src="https://gist.github.com/SibeeshVenu/6f2681e284b50352ed9e2457ef182515.js"></script>



<script src="https://gist.github.com/SibeeshVenu/22b96305a7e43336e28a3109883fce47.js"></script>



<p>Have a look at the code above.</p>



<p>I have an ErrorLogger class that writes an error into database. The method is actually called from another class ApplicationWatcher.<br>In a later stage, if I want to send an email instead of writing into the database, this design will not suffice. I will have created another class that has a method that sends an email and creates its instance in the application watches.</p>



<h4 class="wp-block-heading">What is Data Encapsulation and explain its Implementation?</h4>



<p>To know about the Data encapsulation in C#, I recommend you to read here:<br><a href="http://www.tutorialspoint.com/csharp/csharp_encapsulation.htm" target="_blank" rel="noopener noreferrer">Data Encapsulation and Its Implementation </a><br>That&#8217;s all. Have a great day.</p>



<h3 class="wp-block-heading">Conclusion</h3>



<p>Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>



<h3 class="wp-block-heading">Your turn. What do you think?</h3>



<p>A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>



<p>Kindest Regards<br>Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/c-sharp-interview-questions-and-answers/feed/</wfw:commentRss>
			<slash:comments>8</slash:comments>
		
		
			</item>
		<item>
		<title>Using Spire.PDF In Asp.Net</title>
		<link>https://sibeeshpassion.com/using-spire-pdf-in-asp-net/</link>
					<comments>https://sibeeshpassion.com/using-spire-pdf-in-asp-net/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Mon, 24 Aug 2015 16:41:58 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Products]]></category>
		<category><![CDATA[Spire.PDF]]></category>
		<category><![CDATA[Adding a watermark To PDF]]></category>
		<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[Convert PDF Page to Image]]></category>
		<category><![CDATA[Decryption of PDF File]]></category>
		<category><![CDATA[Encrypting PDF File]]></category>
		<category><![CDATA[Using Spire]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=10081</guid>

					<description><![CDATA[In this article we are going to see a new product Spire.PDF which helps us to create, manipulate PDF and many more. This product has been introduced by the company E-Iceblue. The company has introduced so many products like this. For example Spire.Doc, Spire.XLS. I hope you have read my articles under these categories. If you have not read them, I suggest you to rad here. Using Spire.Doc Using Spire.Xls Working With Charts Using Spire.Xls Download source code Using Spire PDF Background As you all know a PDF is a most accurate and effective format of a document. A document [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this article we are going to see a new product <em>Spire.PDF</em> which helps us to create, manipulate PDF and many more. This product has been introduced by the company <a href="http://www.e-iceblue.com/" target="_blank" rel="noopener">E-Iceblue</a>. The company has introduced so many products like this. For example Spire.Doc, Spire.XLS. I hope you have read my articles under these categories. If you have not read them, I suggest you to rad here.</p>
<li><a href="http://sibeeshpassion.com/using-spire-doc-introduction/" target="_blank" rel="noopener">Using Spire.Doc</a></li>
<li><a href="http://sibeeshpassion.com/using-spire-xls/" target="_blank" rel="noopener">Using Spire.Xls</a></li>
<li><a href="http://sibeeshpassion.com/working-with-charts-using-spire-xls/" target="_blank" rel="noopener">Working With Charts Using Spire.Xls</a></li>
<p><strong>Download source code </strong></p>
<p><a href="http://sibeeshpassion.com/download/UsingSpirePDF.rar" target="_blank" rel="noopener">Using Spire PDF</a></p>
<p><strong>Background</strong></p>
<p>As you all know a PDF is a most accurate and effective format of a document. A document is very important in our life, so we create PDF files. Now coming to the matter, As we all are developers, we develops anything that is needed. But have you ever tried creating and managing PDF file? Awww!. That&#8217;s a quite difficult task right? Still it is possible. &#8220;Everything is possible, the word impossible itself says I am possible&#8221;. Now It is time to introduce you a product which let you do these task in an easy manner. So that means, you are able to do these task with a little effort. </p>
<p><strong>Create a new Project</strong></p>
<p>Now we will create a new Project in our Visual studio.</p>
<p><div id="attachment_10091" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Using_Spire_PDF_Create_New_Project-e1440348497731.png"><img decoding="async" aria-describedby="caption-attachment-10091" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Using_Spire_PDF_Create_New_Project-e1440348497731.png" alt="Using_Spire_PDF_Create_New_Project" width="650" height="397" class="size-full wp-image-10091" srcset="/wp-content/uploads/2015/08/Using_Spire_PDF_Create_New_Project-e1440348497731.png 650w, /wp-content/uploads/2015/08/Using_Spire_PDF_Create_New_Project-e1440348497731-300x183.png 300w, /wp-content/uploads/2015/08/Using_Spire_PDF_Create_New_Project-e1440348497731-400x244.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-10091" class="wp-caption-text">Using_Spire_PDF_Create_New_Project</p></div></p>
<p><strong>Add License Information To Project</strong></p>
<p>I am using evaluation version with one month temporary license. There are free versions also available for spire.pdf with some limitation. You can try that. </p>
<p><div id="attachment_10101" style="width: 664px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Using_Spire_PDF_Add_License_To_Project.png"><img decoding="async" aria-describedby="caption-attachment-10101" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Using_Spire_PDF_Add_License_To_Project.png" alt="Using_Spire_PDF_Add_License_To_Project" width="654" height="150" class="size-full wp-image-10101" srcset="/wp-content/uploads/2015/08/Using_Spire_PDF_Add_License_To_Project.png 654w, /wp-content/uploads/2015/08/Using_Spire_PDF_Add_License_To_Project-300x69.png 300w, /wp-content/uploads/2015/08/Using_Spire_PDF_Add_License_To_Project-400x92.png 400w" sizes="(max-width: 654px) 100vw, 654px" /></a><p id="caption-attachment-10101" class="wp-caption-text">Using_Spire_PDF_Add_License_To_Project</p></div></p>
<p><strong>Download the files</strong></p>
<p>You can always the needed files from here: <a href="http://www.e-iceblue.com/Download/download-pdf-for-net-now.html" target="_blank" rel="noopener">Download Spire.PDF</a></p>
<p><strong>Install Spire.PDF</strong></p>
<p>Now click on the exe file after you extract the downloaded file. The installation will get started then.</p>
<p><div id="attachment_10121" style="width: 519px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Using_Spire_PDF_Installing.png"><img decoding="async" aria-describedby="caption-attachment-10121" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Using_Spire_PDF_Installing.png" alt="Using_Spire_PDF_Installing" width="509" height="399" class="size-full wp-image-10121" srcset="/wp-content/uploads/2015/08/Using_Spire_PDF_Installing.png 509w, /wp-content/uploads/2015/08/Using_Spire_PDF_Installing-300x235.png 300w, /wp-content/uploads/2015/08/Using_Spire_PDF_Installing-400x314.png 400w" sizes="(max-width: 509px) 100vw, 509px" /></a><p id="caption-attachment-10121" class="wp-caption-text">Using_Spire_PDF_Installing</p></div></p>
<p><div id="attachment_10131" style="width: 519px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Using_Spire_PDF_Installing_Complete.png"><img decoding="async" aria-describedby="caption-attachment-10131" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Using_Spire_PDF_Installing_Complete.png" alt="Using_Spire_PDF_Installing_Complete" width="509" height="399" class="size-full wp-image-10131" srcset="/wp-content/uploads/2015/08/Using_Spire_PDF_Installing_Complete.png 509w, /wp-content/uploads/2015/08/Using_Spire_PDF_Installing_Complete-300x235.png 300w, /wp-content/uploads/2015/08/Using_Spire_PDF_Installing_Complete-400x314.png 400w" sizes="(max-width: 509px) 100vw, 509px" /></a><p id="caption-attachment-10131" class="wp-caption-text">Using_Spire_PDF_Installing_Complete</p></div></p>
<p>So Shall we start?</p>
<p>Once you Installed, you are ready to go. We will start with a “Simple Web Application” . I hope you have a created a new web application and added your license as suggested before. Now create a page.</p>
<p>So your page will be looking as follows.</p>
<p>[html]<br />
&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeBehind=&quot;Default.aspx.cs&quot; Inherits=&quot;UsingSpirePDF.Default&quot; %&gt;</p>
<p>&lt;!DOCTYPE html&gt;</p>
<p>&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;<br />
&lt;head runat=&quot;server&quot;&gt;<br />
    &lt;title&gt;&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
    &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;<br />
    &lt;div&gt;</p>
<p>    &lt;/div&gt;<br />
    &lt;/form&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
[/html]</p>
<p>Now right click on your project and click add reference, in the browse tab find out the folder in which you have installed spire.pdf. Usually it will be in the C:\Program Files\e-iceblue\Spire.pdf. Now just find your framework version from BIN folder and add Spire.pdf.dll</p>
<p><div id="attachment_10241" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Using_Spire_PDF_Adding_Reference-e1440429536607.png"><img decoding="async" aria-describedby="caption-attachment-10241" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Using_Spire_PDF_Adding_Reference-e1440429536607.png" alt="Using_Spire_PDF_Adding_Reference" width="650" height="447" class="size-full wp-image-10241" srcset="/wp-content/uploads/2015/08/Using_Spire_PDF_Adding_Reference-e1440429536607.png 650w, /wp-content/uploads/2015/08/Using_Spire_PDF_Adding_Reference-e1440429536607-300x206.png 300w, /wp-content/uploads/2015/08/Using_Spire_PDF_Adding_Reference-e1440429536607-160x110.png 160w, /wp-content/uploads/2015/08/Using_Spire_PDF_Adding_Reference-e1440429536607-400x275.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-10241" class="wp-caption-text">Using_Spire_PDF_Adding_Reference</p></div></p>
<p>Now we have added reference too. So shall we start coding ?</p>
<p><strong>Using the code</strong></p>
<p>There are so many features available, we will look in to most useful features which you might found useful.</p>
<p><strong>Convert PDF Page to Image</strong></p>
<p>In this part, we will see how can we convert a PDF file to image with a specific resolution. It is so simple and powerful.</p>
<p>We will create a button as follows.</p>
<p>[html]<br />
&lt;asp:Button ID=&quot;btnConvertToImage&quot; runat=&quot;server&quot; Text=&quot;Convert To Image&quot; /&gt;<br />
[/html]</p>
<p>Next we need to add the needed references.</p>
<p>[csharp]<br />
using Spire.Pdf;<br />
using Spire.Pdf.Graphics;<br />
using System;<br />
using System.Drawing;<br />
[/csharp]</p>
<p>And in the button click we can write the preceding codes.</p>
<p>[csharp]<br />
 protected void btnConvertToImage_Click(object sender, EventArgs e)<br />
        {<br />
            try<br />
            {<br />
                PdfDocument documemt = new PdfDocument();<br />
                documemt.LoadFromFile(@&quot;D:\\sibeeshpassion.pdf&quot;);<br />
                Image image = documemt.SaveAsImage(0, PdfImageType.Bitmap, 400, 400);<br />
                image.Save(@&quot;D:\\result.jpg&quot;);<br />
                documemt.Close();<br />
            }<br />
            catch (Exception)<br />
            {</p>
<p>                throw;<br />
            }<br />
        }<br />
[/csharp]</p>
<p>As you can see we are calling the below function to generate the image.</p>
<p>[csharp]<br />
documemt.SaveAsImage(0, PdfImageType.Bitmap, 400, 400);<br />
[/csharp]</p>
<p>And this function has overloaded as in the below image.</p>
<p><div id="attachment_10251" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Using_Spire_PDF_Covert_PDF_To_Image.png"><img decoding="async" aria-describedby="caption-attachment-10251" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Using_Spire_PDF_Covert_PDF_To_Image-e1440431907162.png" alt="Using_Spire_PDF_Covert_PDF_To_Image" width="650" height="97" class="size-full wp-image-10251" srcset="/wp-content/uploads/2015/08/Using_Spire_PDF_Covert_PDF_To_Image-e1440431907162.png 650w, /wp-content/uploads/2015/08/Using_Spire_PDF_Covert_PDF_To_Image-e1440431907162-300x45.png 300w, /wp-content/uploads/2015/08/Using_Spire_PDF_Covert_PDF_To_Image-e1440431907162-400x60.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-10251" class="wp-caption-text">Using_Spire_PDF_Covert_PDF_To_Image</p></div></p>
<p>Here we are taking the pdf file <em><a href="http://sibeeshpassion.com/download/sibeeshpassion.pdf" target="_blank" rel="noopener">sibeeshpassion.pdf</a></em> and we are getting a image as follows as output. </p>
<p><div id="attachment_10261" style="width: 520px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Using_Spire_PDF_Covert_PDF_To_Image_Output.png"><img decoding="async" aria-describedby="caption-attachment-10261" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Using_Spire_PDF_Covert_PDF_To_Image_Output.png" alt="Using_Spire_PDF_Covert_PDF_To_Image_Output" width="510" height="724" class="size-full wp-image-10261" srcset="/wp-content/uploads/2015/08/Using_Spire_PDF_Covert_PDF_To_Image_Output.png 251w, /wp-content/uploads/2015/08/Using_Spire_PDF_Covert_PDF_To_Image_Output-211x300.png 211w, /wp-content/uploads/2015/08/Using_Spire_PDF_Covert_PDF_To_Image_Output-400x568.png 400w, /wp-content/uploads/2015/08/Using_Spire_PDF_Covert_PDF_To_Image_Output-423x600.png 423w" sizes="(max-width: 510px) 100vw, 510px" /></a><p id="caption-attachment-10261" class="wp-caption-text">Using_Spire_PDF_Covert_PDF_To_Image_Output</p></div></p>
<p>Cool Right?</p>
<p>Now we will see another implementation.</p>
<p><strong>Security</strong></p>
<p>There are few many security options are also available with this package like Encryption and Decryption of the pdf file and creating a digital signature and many more.</p>
<p><strong>Encrypting PDF File</strong></p>
<p>In this step, we are going to set a password for our pdf document.</p>
<p>To work with security, you need to add a new reference as follows.</p>
<p>[csharp]<br />
using Spire.Pdf.Security;<br />
[/csharp]</p>
<p>Now add a new button as follows.</p>
<p>[html]<br />
&lt;asp:Button ID=&quot;btnEncryptPDF&quot; runat=&quot;server&quot; Text=&quot;Encrypt PDF&quot; OnClick=&quot;btnEncryptPDF_Click&quot;/&gt;<br />
[/html]</p>
<p>Now it is time for click event.</p>
<p>[csharp]<br />
protected void btnEncryptPDF_Click(object sender, EventArgs e)<br />
        {<br />
            try<br />
            {<br />
                PdfDocument doc = new PdfDocument(@&quot;D:\\sibeeshpassion.pdf&quot;, &quot;sibeeshpassionEncrypted&quot;);<br />
                doc.Security.KeySize = PdfEncryptionKeySize.Key256Bit;<br />
                doc.Security.OwnerPassword = &quot;sibeeshpassion&quot;;<br />
                doc.Security.UserPassword = &quot;sibeesh&quot;;<br />
                doc.Security.Permissions = PdfPermissionsFlags.Print | PdfPermissionsFlags.CopyContent;<br />
            }<br />
            catch (Exception)<br />
            {</p>
<p>                throw;<br />
            }<br />
        }<br />
[/csharp]</p>
<p>Three kind of pdf key size are available as shown in the below image.</p>
<p><div id="attachment_10271" style="width: 663px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Using_Spire_PDF_Possible_Key.png"><img decoding="async" aria-describedby="caption-attachment-10271" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Using_Spire_PDF_Possible_Key.png" alt="Using_Spire_PDF_Possible_Key" width="653" height="108" class="size-full wp-image-10271" srcset="/wp-content/uploads/2015/08/Using_Spire_PDF_Possible_Key.png 653w, /wp-content/uploads/2015/08/Using_Spire_PDF_Possible_Key-300x50.png 300w, /wp-content/uploads/2015/08/Using_Spire_PDF_Possible_Key-400x66.png 400w" sizes="(max-width: 653px) 100vw, 653px" /></a><p id="caption-attachment-10271" class="wp-caption-text">Using_Spire_PDF_Possible_Key</p></div></p>
<p>And as you can see, we are setting some permission by using the preceding code.</p>
<p>[csharp]<br />
 doc.Security.Permissions = PdfPermissionsFlags.Print | PdfPermissionsFlags.CopyContent;<br />
[/csharp]</p>
<p>There are some other permission options also available.</p>
<p><div id="attachment_10281" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Using_Spire_PDF_Possible_File_Permissions-e1440433409566.png"><img decoding="async" aria-describedby="caption-attachment-10281" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Using_Spire_PDF_Possible_File_Permissions-e1440433409566.png" alt="Using_Spire_PDF_Possible_File_Permissions" width="650" height="244" class="size-full wp-image-10281" srcset="/wp-content/uploads/2015/08/Using_Spire_PDF_Possible_File_Permissions-e1440433409566.png 650w, /wp-content/uploads/2015/08/Using_Spire_PDF_Possible_File_Permissions-e1440433409566-300x113.png 300w, /wp-content/uploads/2015/08/Using_Spire_PDF_Possible_File_Permissions-e1440433409566-400x150.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-10281" class="wp-caption-text">Using_Spire_PDF_Possible_File_Permissions</p></div></p>
<p>Now if you try to open our pdf again, it will ask you for a password which we have set in the above codes. Cool.</p>
<p><strong>Decryption of PDF File</strong></p>
<p>AS we encrypt our pdf file, we need to do decryption also right?</p>
<p>Add an another button.</p>
<p>[html]<br />
&lt;asp:Button ID=&quot;btnDecrypt&quot; runat=&quot;server&quot; Text=&quot;Decrypt PDF&quot; OnClick=&quot;btnDecrypt_Click&quot; /&gt;<br />
[/html] </p>
<p>Add the following code block in the button click event.</p>
<p>[csharp]<br />
try<br />
            {<br />
                PdfDocument doc = new PdfDocument(@&quot;D:\\sibeeshpassion.pdf&quot;, &quot;sibeeshpassionEncrypted&quot;);<br />
                //extract image<br />
                Image image = doc.Pages[0].ImagesInfo[0].Image;<br />
                doc.Close();<br />
                //Save image file.<br />
                image.Save(&quot;sibeeshpassionDecrypted.png&quot;, System.Drawing.Imaging.ImageFormat.Png);<br />
                //Launching the image file.<br />
                System.Diagnostics.Process.Start(&quot;sibeeshpassionDecrypted.png&quot;);</p>
<p>            }<br />
            catch (Exception ex)<br />
            {</p>
<p>                throw;<br />
            }<br />
[/csharp]</p>
<p>Once you run the above codes, your pdf file will be decrypted.</p>
<p><strong>Watermark</strong></p>
<p>You can add watermark to your pdf file easily with this package. </p>
<p><strong>Adding a watermark</strong></p>
<p>There are two kind of watermarks. One is text watermark and other is image watermark.</p>
<p>Now we will add another button.</p>
<p>[html]<br />
&lt;asp:Button ID=&quot;btnAddImageWatermark&quot; runat=&quot;server&quot; Text=&quot;Add Image Watermark&quot; OnClick=&quot;btnAddImageWatermark_Click&quot;  /&gt;<br />
[/html]</p>
<p>And in the button click we can write the preceding codes.</p>
<p>[csharp]<br />
protected void btnAddImageWatermark_Click(object sender, EventArgs e)<br />
        {<br />
            try<br />
            {<br />
                PdfDocument doc = new PdfDocument(&quot;D:\\Sibi.pdf&quot;, &quot;Sibi&quot;);<br />
                Image img = Image.FromFile(&quot;D:\\sibi.jpg&quot;);<br />
                doc.Pages[0].BackgroundImage = img;<br />
                doc.SaveToFile(&quot;D:\\Sibeesh.pdf&quot;);<br />
                doc.Close();</p>
<p>            }<br />
            catch (Exception)<br />
            {</p>
<p>                throw;<br />
            }<br />
        }<br />
[/csharp]</p>
<p>As you can see we are taking a pdf file and add a watermark image to the file and at last we save it to an another file. In this case from sibi.pdf to sibeesh.pdf.</p>
<p>I am taking <a href="http://sibeeshpassion.com/content/images/sibi.jpg" target="_blank" rel="noopener">sibi.jpg</a> as the water mark image, so you can see the pdf file with watermarked image as follows.</p>
<p><div id="attachment_10311" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Using_Spire_PDF_Adding_Watermark-e1440437182738.png"><img decoding="async" aria-describedby="caption-attachment-10311" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Using_Spire_PDF_Adding_Watermark-e1440437182738.png" alt="Using_Spire_PDF_Adding_Watermark" width="650" height="601" class="size-full wp-image-10311" srcset="/wp-content/uploads/2015/08/Using_Spire_PDF_Adding_Watermark-e1440437182738.png 650w, /wp-content/uploads/2015/08/Using_Spire_PDF_Adding_Watermark-e1440437182738-300x277.png 300w, /wp-content/uploads/2015/08/Using_Spire_PDF_Adding_Watermark-e1440437182738-400x370.png 400w, /wp-content/uploads/2015/08/Using_Spire_PDF_Adding_Watermark-e1440437182738-649x600.png 649w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-10311" class="wp-caption-text">Using_Spire_PDF_Adding_Watermark</p></div></p>
<p><em>Please be noted that, you can convert your PDF file to any other file format, there are plenty of options available. Please try that too. I have given only few options which I use always.</em></p>
<p><strong>Conclusion</strong></p>
<p>These are the features I loved using Spire.PDF. It is much effective and simple. What do you think about this? Are you using Spire.PDF yet? Do you plan to try this?Did I miss anything that you may think which is needed?. I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<p><strong>Your turn. What do you think?</strong></p>
<p>A blog isn&#8217;t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you&#8217;re better off posting it on Stack Overflow instead of commenting here. Tweet or email me a link to your question there and I&#8217;ll definitely try to help if I am able to.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/using-spire-pdf-in-asp-net/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Working With Charts Using Spire.XLS</title>
		<link>https://sibeeshpassion.com/working-with-charts-using-spire-xls/</link>
					<comments>https://sibeeshpassion.com/working-with-charts-using-spire-xls/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Tue, 11 Aug 2015 15:45:19 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Products]]></category>
		<category><![CDATA[Spire.XLS]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[chart]]></category>
		<category><![CDATA[Charts Using Spire.XLS]]></category>
		<category><![CDATA[Column Charts]]></category>
		<category><![CDATA[Pie Charts]]></category>
		<category><![CDATA[Save Excel Charts as Images]]></category>
		<category><![CDATA[Spire.XLs]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=8751</guid>

					<description><![CDATA[Today we are going to see an another series of new product Spire.XLS which helps us to create, manipulate, convert EXCEL file to other formats, create charts dynamically and many more. This product has been introduced by the company E-Iceblue. I hope you have read my article of Spire.Doc and Spire.XLS. If you have not read it, I recommend you to read it here: Using Spire.XLS Background As you all know, charts are the graphical representations of our data. It is much easier to understand our data if it is in a graphical form. Am I right? It is easy [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Today we are going to see an another series of new product <em>Spire.XLS</em> which helps us to create, manipulate, convert EXCEL file to other formats, create charts dynamically and many more. This product has been introduced by the company <a href="http://www.e-iceblue.com/" target="_blank" rel="noopener">E-Iceblue</a>. I hope you have read my article of <em>Spire.Doc</em> and <em>Spire.XLS</em>. If you have not read it, I recommend you to read it here: <a href="http://sibeeshpassion.com/using-spire-xls/" target="_blank" rel="noopener">Using Spire.XLS</a></p>
<p><strong>Background</strong></p>
<p>As you all know, charts are the graphical representations of our data. It is much easier to understand our data if it is in a graphical form. Am I right? It is easy to create a static chart, but what about a dynamic one? It will be bit tough right? But by using Spire.XLS, we can create any kind of charts easily. In this post, we will see those implementations. </p>
<p><strong>Download the files</strong></p>
<p>You can always get the needed files from here: <a href="http://www.e-iceblue.com/Download/download-excel-for-net-now.html" target="_blank" rel="noopener">Download Spire.XLS</a></p>
<p><strong>Install Spire.XLS</strong></p>
<p>I am using evaluation version with one month temporary license. There are free versions also available for spire.xls with some limitation. You can try that. Now click on the exe file after you extract the downloaded file. The installation will get started then.</p>
<p><img decoding="async" src="http://sibeeshpassion.com/content/images/InstallSpireXls.png" alt="Using Spire XLS" /></p>
<p><strong>Using the code</strong></p>
<p>Before starting with coding you need to add the needed namespaces as follows.</p>
<p>[csharp]<br />
using Spire.Xls;<br />
using System.Drawing;<br />
[/csharp]</p>
<p>First of all create a form and then a button, in the button click add the following lines of codes.</p>
<p><strong>C# Code</strong></p>
<p>[csharp]<br />
  private void button1_Click(object sender, EventArgs e)<br />
        {<br />
            try<br />
            {<br />
                //Create a new workbook<br />
                Workbook workbook = new Workbook();<br />
                //Initialize worksheet<br />
                workbook.CreateEmptySheets(1);<br />
                Worksheet sheet = workbook.Worksheets[0];<br />
                //Set sheet name<br />
                sheet.Name = &quot;Chart data&quot;;<br />
                //Set the grid lines invisible<br />
                sheet.GridLinesVisible = false;<br />
                //Create a chart<br />
                Chart chart = sheet.Charts.Add(ExcelChartType.Pie3D);<br />
                //Set region of chart data<br />
                chart.DataRange = sheet.Range[&quot;B2:B5&quot;];<br />
                chart.SeriesDataFromRange = false;<br />
                //Set position of chart<br />
                chart.LeftColumn = 1;<br />
                chart.TopRow = 6;<br />
                chart.RightColumn = 9;<br />
                chart.BottomRow = 25;<br />
                //Chart title<br />
                chart.ChartTitle = &quot;Sales by year&quot;;<br />
                chart.ChartTitleArea.IsBold = true;<br />
                chart.ChartTitleArea.Size = 12;<br />
                //Initialize the chart series<br />
                Spire.Xls.Charts.ChartSerie cs = chart.Series[0];<br />
                //Chart Labels resource<br />
                cs.CategoryLabels = sheet.Range[&quot;A2:A5&quot;];<br />
                //Chart value resource<br />
                cs.Values = sheet.Range[&quot;B2:B5&quot;];<br />
                //Set the value visible in the chart<br />
                cs.DataPoints.DefaultDataPoint.DataLabels.HasValue = true;<br />
                //Year<br />
                sheet.Range[&quot;A1&quot;].Value = &quot;Year&quot;;<br />
                sheet.Range[&quot;A2&quot;].Value = &quot;2002&quot;;<br />
                sheet.Range[&quot;A3&quot;].Value = &quot;2003&quot;;<br />
                sheet.Range[&quot;A4&quot;].Value = &quot;2004&quot;;<br />
                sheet.Range[&quot;A5&quot;].Value = &quot;2005&quot;;<br />
                //Sales<br />
                sheet.Range[&quot;B1&quot;].Value = &quot;Sales&quot;;<br />
                sheet.Range[&quot;B2&quot;].NumberValue = 4000;<br />
                sheet.Range[&quot;B3&quot;].NumberValue = 6000;<br />
                sheet.Range[&quot;B4&quot;].NumberValue = 7000;<br />
                sheet.Range[&quot;B5&quot;].NumberValue = 8500;<br />
                //Style<br />
                sheet.Range[&quot;A1:B1&quot;].Style.Font.IsBold = true;<br />
                sheet.Range[&quot;A2:B2&quot;].Style.KnownColor = ExcelColors.LightYellow;<br />
                sheet.Range[&quot;A3:B3&quot;].Style.KnownColor = ExcelColors.LightGreen1;<br />
                sheet.Range[&quot;A4:B4&quot;].Style.KnownColor = ExcelColors.LightOrange;<br />
                sheet.Range[&quot;A5:B5&quot;].Style.KnownColor = ExcelColors.LightTurquoise;<br />
                //Border<br />
                sheet.Range[&quot;A1:B5&quot;].Style.Borders[BordersLineType.EdgeTop].Color = Color.FromArgb(0, 0, 128);<br />
                sheet.Range[&quot;A1:B5&quot;].Style.Borders[BordersLineType.EdgeTop].LineStyle = LineStyleType.Thin;<br />
                sheet.Range[&quot;A1:B5&quot;].Style.Borders[BordersLineType.EdgeBottom].Color = Color.FromArgb(0, 0, 128);<br />
                sheet.Range[&quot;A1:B5&quot;].Style.Borders[BordersLineType.EdgeBottom].LineStyle = LineStyleType.Thin;<br />
                sheet.Range[&quot;A1:B5&quot;].Style.Borders[BordersLineType.EdgeLeft].Color = Color.FromArgb(0, 0, 128);<br />
                sheet.Range[&quot;A1:B5&quot;].Style.Borders[BordersLineType.EdgeLeft].LineStyle = LineStyleType.Thin;<br />
                sheet.Range[&quot;A1:B5&quot;].Style.Borders[BordersLineType.EdgeRight].Color = Color.FromArgb(0, 0, 128);<br />
                sheet.Range[&quot;A1:B5&quot;].Style.Borders[BordersLineType.EdgeRight].LineStyle = LineStyleType.Thin;<br />
                //Number format<br />
                sheet.Range[&quot;B2:C5&quot;].Style.NumberFormat = &quot;\&quot;$\&quot;#,##0&quot;;<br />
                chart.PlotArea.Fill.Visible = false;<br />
                //Save the file<br />
                workbook.SaveToFile(&quot;Sample.xls&quot;);<br />
                //Launch the file<br />
                System.Diagnostics.Process.Start(&quot;Sample.xls&quot;);<br />
            }<br />
            catch (Exception)<br />
            {</p>
<p>                throw;<br />
            }<br />
        }<br />
[/csharp]</p>
<p><strong>VB.NET Code</strong></p>
<p>[vb]<br />
 &#8216;Create a new workbook<br />
        Dim workbook As New Workbook()<br />
        &#8216;Initialize worksheet<br />
        workbook.CreateEmptySheets(1)<br />
        Dim sheet As Worksheet = workbook.Worksheets(0)<br />
        &#8216;Set sheet name<br />
        sheet.Name = &quot;Chart data&quot;<br />
        &#8216;Set the grid lines invisible<br />
        sheet.GridLinesVisible = False<br />
        &#8216;Create a chart<br />
        Dim chart As Chart = sheet.Charts.Add(ExcelChartType.Pie3D)<br />
        &#8216;Set region of chart data<br />
        chart.DataRange = sheet.Range(&quot;B2:B5&quot;)<br />
        chart.SeriesDataFromRange = False<br />
        &#8216;Set position of chart<br />
        chart.LeftColumn = 1<br />
        chart.TopRow = 6<br />
        chart.RightColumn = 9<br />
        chart.BottomRow = 25<br />
        &#8216;Chart title<br />
        chart.ChartTitle = &quot;Sales by year&quot;<br />
        chart.ChartTitleArea.IsBold = True<br />
        chart.ChartTitleArea.Size = 12<br />
        &#8216;Set the chart<br />
        Dim cs As Spire.Xls.Charts.ChartSerie = chart.Series(0)<br />
        &#8216;Chart Labels resource<br />
        cs.CategoryLabels = sheet.Range(&quot;A2:A5&quot;)<br />
        &#8216;Chart value resource<br />
        cs.Values = sheet.Range(&quot;B2:B5&quot;)<br />
        &#8216;Set the value visible in the chart<br />
        cs.DataPoints.DefaultDataPoint.DataLabels.HasValue = True<br />
        &#8216;Year<br />
        sheet.Range(&quot;A1&quot;).Value = &quot;Year&quot;<br />
        sheet.Range(&quot;A2&quot;).Value = &quot;2002&quot;<br />
        sheet.Range(&quot;A3&quot;).Value = &quot;2003&quot;<br />
        sheet.Range(&quot;A4&quot;).Value = &quot;2004&quot;<br />
        sheet.Range(&quot;A5&quot;).Value = &quot;2005&quot;<br />
        &#8216;Sales<br />
        sheet.Range(&quot;B1&quot;).Value = &quot;Sales&quot;<br />
        sheet.Range(&quot;B2&quot;).NumberValue = 4000<br />
        sheet.Range(&quot;B3&quot;).NumberValue = 6000<br />
        sheet.Range(&quot;B4&quot;).NumberValue = 7000<br />
        sheet.Range(&quot;B5&quot;).NumberValue = 8500<br />
        &#8216;Style<br />
        sheet.Range(&quot;A1:B1&quot;).Style.Font.IsBold = True<br />
        sheet.Range(&quot;A2:B2&quot;).Style.KnownColor = ExcelColors.LightYellow<br />
        sheet.Range(&quot;A3:B3&quot;).Style.KnownColor = ExcelColors.LightGreen1<br />
        sheet.Range(&quot;A4:B4&quot;).Style.KnownColor = ExcelColors.LightOrange<br />
        sheet.Range(&quot;A5:B5&quot;).Style.KnownColor = ExcelColors.LightTurquoise<br />
        &#8216;Border<br />
        sheet.Range(&quot;A1:B5&quot;).Style.Borders(BordersLineType.EdgeTop).Color = Color.FromArgb(0, 0, 128)<br />
        sheet.Range(&quot;A1:B5&quot;).Style.Borders(BordersLineType.EdgeTop).LineStyle = LineStyleType.Thin<br />
        sheet.Range(&quot;A1:B5&quot;).Style.Borders(BordersLineType.EdgeBottom).Color = Color.FromArgb(0, 0, 128)<br />
        sheet.Range(&quot;A1:B5&quot;).Style.Borders(BordersLineType.EdgeBottom).LineStyle = LineStyleType.Thin<br />
        sheet.Range(&quot;A1:B5&quot;).Style.Borders(BordersLineType.EdgeLeft).Color = Color.FromArgb(0, 0, 128)<br />
        sheet.Range(&quot;A1:B5&quot;).Style.Borders(BordersLineType.EdgeLeft).LineStyle = LineStyleType.Thin<br />
        sheet.Range(&quot;A1:B5&quot;).Style.Borders(BordersLineType.EdgeRight).Color = Color.FromArgb(0, 0, 128)<br />
        sheet.Range(&quot;A1:B5&quot;).Style.Borders(BordersLineType.EdgeRight).LineStyle = LineStyleType.Thin<br />
        &#8216;Number format<br />
        sheet.Range(&quot;B2:C5&quot;).Style.NumberFormat = &quot;&quot;&quot;$&quot;&quot;#,##0&quot;<br />
        chart.PlotArea.Fill.Visible = False<br />
        &#8216;Save doc file.<br />
        workbook.SaveToFile(&quot;Sample.xls&quot;)<br />
        &#8216;Launch the MS Word file.<br />
        System.Diagnostics.Process.Start(&quot;Sample.xls&quot;)<br />
[/vb]</p>
<p>In the above lines code, we are creating a pie chart by giving some settings and data and load it. Now if you run you will get an output as follows.</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Create_Charts_Using_SpireXLS-e1439222337541.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Create_Charts_Using_SpireXLS-e1439222337541.png" alt="Create_Charts_Using_SpireXLS" width="650" height="261" class="alignnone size-full wp-image-8761" srcset="/wp-content/uploads/2015/08/Create_Charts_Using_SpireXLS-e1439222337541.png 650w, /wp-content/uploads/2015/08/Create_Charts_Using_SpireXLS-e1439222337541-300x120.png 300w, /wp-content/uploads/2015/08/Create_Charts_Using_SpireXLS-e1439222337541-400x161.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a></p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Create_Charts_Using_SpireXLS_Output.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Create_Charts_Using_SpireXLS_Output.png" alt="Create_Charts_Using_SpireXLS_Output" width="581" height="510" class="alignnone size-full wp-image-8771" srcset="/wp-content/uploads/2015/08/Create_Charts_Using_SpireXLS_Output.png 581w, /wp-content/uploads/2015/08/Create_Charts_Using_SpireXLS_Output-300x263.png 300w, /wp-content/uploads/2015/08/Create_Charts_Using_SpireXLS_Output-400x351.png 400w" sizes="(max-width: 581px) 100vw, 581px" /></a></p>
<p>In the above mentioned lines of codes, we are doing so many processes, those processes are listed below.</p>
<li>Creating a new workbook</li>
<li>Initialize worksheet newly created</li>
<li>Set sheet name of worksheet</li>
<li>Set the grid lines invisible</li>
<li>Creating a chart</li>
<li>Set region of chart data</li>
<li>Set position of chart</li>
<li>Set Chart title</li>
<li>Initialize the chart series</li>
<li>Setting Chart Labels resource</li>
<li>Setting Chart value resource</li>
<li>Set the value visible in the chart</li>
<li>Apply Styles</li>
<li>Apply Borders</li>
<li>Give Number format if necessary</li>
<li>Save the file</li>
<li>At last Launch the file</li>
<p>Wow!. That&#8217;s cool right?</p>
<p>Not yet finished!. There are so many things you can try with your sheet object. I suggest you to try those. You will get surprised.</p>
<p><div id="attachment_10031" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Working_With_Charts_Using_Spire-e1440082383956.png"><img decoding="async" aria-describedby="caption-attachment-10031" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Working_With_Charts_Using_Spire-e1440082383956.png" alt="Working With Charts Using Spire XLS Sheet Object" width="650" height="233" class="size-full wp-image-10031" srcset="/wp-content/uploads/2015/08/Working_With_Charts_Using_Spire-e1440082383956.png 650w, /wp-content/uploads/2015/08/Working_With_Charts_Using_Spire-e1440082383956-300x108.png 300w, /wp-content/uploads/2015/08/Working_With_Charts_Using_Spire-e1440082383956-400x143.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-10031" class="wp-caption-text">Working With Charts Using Spire XLS Sheet Object</p></div></p>
<p><div id="attachment_10041" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Working_With_Charts_Using_Spire1-e1440082428977.png"><img decoding="async" aria-describedby="caption-attachment-10041" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Working_With_Charts_Using_Spire1-e1440082428977.png" alt="Working With Charts Using Spire XLS Sheet Object" width="650" height="270" class="size-full wp-image-10041" srcset="/wp-content/uploads/2015/08/Working_With_Charts_Using_Spire1-e1440082428977.png 650w, /wp-content/uploads/2015/08/Working_With_Charts_Using_Spire1-e1440082428977-300x125.png 300w, /wp-content/uploads/2015/08/Working_With_Charts_Using_Spire1-e1440082428977-400x166.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-10041" class="wp-caption-text">Working With Charts Using Spire XLS Sheet Object</p></div></p>
<p>If you want you can set different chart types too, it will give you a great design in your chart. The most useful chart types which I uses is Bar3DClustered, 3DBubble, Bubble, Column3D and many more.</p>
<p><div id="attachment_10051" style="width: 660px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Working_With_Charts_Using_Spire_XLS_Chart_Object.png"><img decoding="async" aria-describedby="caption-attachment-10051" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Working_With_Charts_Using_Spire_XLS_Chart_Object-e1440082676189.png" alt="Working_With_Charts_Using_Spire_XLS_Chart_Object" width="650" height="195" class="size-full wp-image-10051" srcset="/wp-content/uploads/2015/08/Working_With_Charts_Using_Spire_XLS_Chart_Object-e1440082676189.png 650w, /wp-content/uploads/2015/08/Working_With_Charts_Using_Spire_XLS_Chart_Object-e1440082676189-300x90.png 300w, /wp-content/uploads/2015/08/Working_With_Charts_Using_Spire_XLS_Chart_Object-e1440082676189-400x120.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a><p id="caption-attachment-10051" class="wp-caption-text">Working_With_Charts_Using_Spire_XLS_Chart_Object</p></div></p>
<p>This product gives you many ways to make your chart in the way you like. There are plenty of options available to so so like you can set the Legend Position by using LegendPositionType property.</p>
<p>Next we will see how we can implement Column chart, what ever we have discusses will be same for every charts, but it may have some different properties which is strictly depends on the chart type. </p>
<p><strong>Column Chart</strong></p>
<p>Now we will create an another button and name it Column Chart. And in the button click you need to add the following codes.</p>
<p><strong>C# Code</strong></p>
<p>[csharp]<br />
private void button2_Click(object sender, EventArgs e)<br />
        {<br />
            try<br />
            {<br />
                //Load Workbook<br />
                Workbook workbook = new Workbook();<br />
                workbook.LoadFromFile(@&quot;D:\Sample.xlsx&quot;);<br />
                Worksheet sheet = workbook.Worksheets[0];<br />
                //Add Chart and Set Chart Data Range<br />
                Chart chart = sheet.Charts.Add(ExcelChartType.ColumnClustered);<br />
                chart.DataRange = sheet.Range[&quot;D1:E17&quot;];<br />
                chart.SeriesDataFromRange = false;<br />
                //Chart Position<br />
                chart.LeftColumn = 1;<br />
                chart.TopRow = 19;<br />
                chart.RightColumn = 8;<br />
                chart.BottomRow = 33;<br />
                //Chart Border<br />
                chart.ChartArea.Border.Weight = ChartLineWeightType.Medium;<br />
                chart.ChartArea.Border.Color = Color.SandyBrown;<br />
                //Chart Title<br />
                chart.ChartTitle = &quot;Parts Sales Info&quot;;<br />
                chart.ChartTitleArea.Font.FontName = &quot;Calibri&quot;;<br />
                chart.ChartTitleArea.Font.Size = 13;<br />
                chart.ChartTitleArea.Font.IsBold = true;<br />
                //Chart Axes<br />
                chart.PrimaryCategoryAxis.Title = &quot;Parts&quot;;<br />
                chart.PrimaryCategoryAxis.Font.Color = Color.Blue;<br />
                chart.PrimaryValueAxis.Title = &quot;Amounts&quot;;<br />
                chart.PrimaryValueAxis.HasMajorGridLines = false;<br />
                chart.PrimaryValueAxis.MaxValue = 350;<br />
                chart.PrimaryValueAxis.TitleArea.TextRotationAngle = 90;<br />
                //Chart Legend<br />
                chart.Legend.Position = LegendPositionType.Right;<br />
                //Save and Launch<br />
                workbook.SaveToFile(&quot;ExcelColumnChart.xlsx&quot;, ExcelVersion.Version2010);<br />
                System.Diagnostics.Process.Start(&quot;ExcelColumnChart.xlsx&quot;);</p>
<p>            }<br />
            catch (Exception)<br />
            {</p>
<p>                throw;<br />
            }<br />
        }<br />
[/csharp]</p>
<p><strong>VB.NET Code</strong></p>
<p>[vb]<br />
 &#8216;Load Workbook<br />
            Dim workbook As New Workbook()<br />
            workbook.LoadFromFile(&quot;E:\Sample.xlsx&quot;)<br />
            Dim sheet As Worksheet = workbook.Worksheets(0)<br />
            &#8216;Add Chart and Set Chart Data Range<br />
            Dim chart As Chart = sheet.Charts.Add(ExcelChartType.ColumnClustered)<br />
            chart.DataRange = sheet.Range(&quot;D1:E17&quot;)<br />
            chart.SeriesDataFromRange = False<br />
            &#8216;Chart Position<br />
            chart.LeftColumn = 1<br />
            chart.TopRow = 19<br />
            chart.RightColumn = 8<br />
            chart.BottomRow = 33<br />
            &#8216;Chart Border<br />
            chart.ChartArea.Border.Weight = ChartLineWeightType.Medium<br />
            chart.ChartArea.Border.Color = Color.SandyBrown<br />
            &#8216;Chart Title<br />
            chart.ChartTitle = &quot;Parts Sales Info&quot;<br />
            chart.ChartTitleArea.Font.FontName = &quot;Calibri&quot;<br />
            chart.ChartTitleArea.Font.Size = 13<br />
            chart.ChartTitleArea.Font.IsBold = True<br />
            &#8216;Chart Axes<br />
            chart.PrimaryCategoryAxis.Title = &quot;Parts&quot;<br />
            chart.PrimaryCategoryAxis.Font.Color = Color.Blue<br />
            chart.PrimaryValueAxis.Title = &quot;Amounts&quot;<br />
            chart.PrimaryValueAxis.HasMajorGridLines = False<br />
            chart.PrimaryValueAxis.MaxValue = 350<br />
            chart.PrimaryValueAxis.TitleArea.TextRotationAngle = 90<br />
            &#8216;Chart Legend<br />
            chart.Legend.Position = LegendPositionType.Right<br />
            &#8216;Save and Launch<br />
            workbook.SaveToFile(&quot;ExcelColumnChart.xlsx&quot;, ExcelVersion.Version2010)<br />
            System.Diagnostics.Process.Start(&quot;ExcelColumnChart.xlsx&quot;)</p>
<p>[/vb]</p>
<p>Now if you run the code, you can see an output as follows.</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/columnchart-e1439304127270.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/columnchart-e1439304127270.png" alt="columnchart" width="650" height="398" class="alignnone size-full wp-image-9061" srcset="/wp-content/uploads/2015/08/columnchart-e1439304127270.png 650w, /wp-content/uploads/2015/08/columnchart-e1439304127270-300x184.png 300w, /wp-content/uploads/2015/08/columnchart-e1439304127270-400x245.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a></p>
<p><strong>Excel Bar Chart</strong></p>
<p>Before going through you must add an new namespace as follows.</p>
<p>[csharp]<br />
using Spire.Xls.Charts;<br />
[/csharp]<br />
Now we will create an another button in our form and in the click event we will write the receding lines of codes.</p>
<p>[csharp]<br />
  private void button1_Click(object sender, EventArgs e)<br />
        {<br />
            try<br />
            {<br />
                Workbook workbook = new Workbook();<br />
                //Initailize worksheet<br />
                workbook.CreateEmptySheets(1);<br />
                Worksheet sheet = workbook.Worksheets[0];<br />
                sheet.Name = &quot;Chart data&quot;;<br />
                sheet.GridLinesVisible = false;<br />
                //Writes chart data<br />
                CreateChartData(sheet);<br />
                //Add a new  chart worsheet to workbook<br />
                Chart chart = sheet.Charts.Add();<br />
                //Set region of chart data<br />
                chart.DataRange = sheet.Range[&quot;A1:C5&quot;];<br />
                chart.SeriesDataFromRange = false;<br />
                //Set position of chart<br />
                chart.LeftColumn = 1;<br />
                chart.TopRow = 6;<br />
                chart.RightColumn = 11;<br />
                chart.BottomRow = 29;<br />
                chart.ChartType = ExcelChartType.Bar3DClustered;<br />
                //Chart title<br />
                chart.ChartTitle = &quot;Sales market by country&quot;;<br />
                chart.ChartTitleArea.IsBold = true;<br />
                chart.ChartTitleArea.Size = 12;<br />
                chart.PrimaryCategoryAxis.Title = &quot;Country&quot;;<br />
                chart.PrimaryCategoryAxis.Font.IsBold = true;<br />
                chart.PrimaryCategoryAxis.TitleArea.IsBold = true;<br />
                chart.PrimaryCategoryAxis.TitleArea.TextRotationAngle = 90;<br />
                chart.PrimaryValueAxis.Title = &quot;Sales(in Dollars)&quot;;<br />
                chart.PrimaryValueAxis.HasMajorGridLines = false;<br />
                chart.PrimaryValueAxis.MinValue = 1000;<br />
                chart.PrimaryValueAxis.TitleArea.IsBold = true;<br />
                foreach (ChartSerie cs in chart.Series)<br />
                {<br />
                    cs.Format.Options.IsVaryColor = true;<br />
                    cs.DataPoints.DefaultDataPoint.DataLabels.HasValue = true;<br />
                }<br />
                chart.Legend.Position = LegendPositionType.Top;<br />
                workbook.SaveToFile(&quot;Sample.xls&quot;);<br />
                ExcelDocViewer(workbook.FileName);</p>
<p>            }<br />
            catch (Exception)<br />
            {<br />
                throw;<br />
            }<br />
        }<br />
[/csharp]</p>
<p>As you can see we are calling a function <em>CreateChartData</em> to generate the data, so now we will write the function body.</p>
<p>[csharp]<br />
private void CreateChartData(Worksheet sheet)<br />
        {<br />
            //Country<br />
            sheet.Range[&quot;A1&quot;].Value = &quot;Country&quot;;<br />
            sheet.Range[&quot;A2&quot;].Value = &quot;Cuba&quot;;<br />
            sheet.Range[&quot;A3&quot;].Value = &quot;Mexico&quot;;<br />
            sheet.Range[&quot;A4&quot;].Value = &quot;France&quot;;<br />
            sheet.Range[&quot;A5&quot;].Value = &quot;German&quot;;<br />
            //Jun<br />
            sheet.Range[&quot;B1&quot;].Value = &quot;Jun&quot;;<br />
            sheet.Range[&quot;B2&quot;].NumberValue = 6000;<br />
            sheet.Range[&quot;B3&quot;].NumberValue = 8000;<br />
            sheet.Range[&quot;B4&quot;].NumberValue = 9000;<br />
            sheet.Range[&quot;B5&quot;].NumberValue = 8500;<br />
            //Jun<br />
            sheet.Range[&quot;C1&quot;].Value = &quot;Aug&quot;;<br />
            sheet.Range[&quot;C2&quot;].NumberValue = 3000;<br />
            sheet.Range[&quot;C3&quot;].NumberValue = 2000;<br />
            sheet.Range[&quot;C4&quot;].NumberValue = 2300;<br />
            sheet.Range[&quot;C5&quot;].NumberValue = 4200;<br />
            //Style<br />
            sheet.Range[&quot;A1:C1&quot;].Style.Font.IsBold = true;<br />
            sheet.Range[&quot;A2:C2&quot;].Style.KnownColor = ExcelColors.LightYellow;<br />
            sheet.Range[&quot;A3:C3&quot;].Style.KnownColor = ExcelColors.LightGreen1;<br />
            sheet.Range[&quot;A4:C4&quot;].Style.KnownColor = ExcelColors.LightOrange;<br />
            sheet.Range[&quot;A5:C5&quot;].Style.KnownColor = ExcelColors.LightTurquoise;<br />
            //Border<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeTop].Color = Color.FromArgb(0, 0, 128);<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeTop].LineStyle = LineStyleType.Thin;<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeBottom].Color = Color.FromArgb(0, 0, 128);<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeBottom].LineStyle = LineStyleType.Thin;<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeLeft].Color = Color.FromArgb(0, 0, 128);<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeLeft].LineStyle = LineStyleType.Thin;<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeRight].Color = Color.FromArgb(0, 0, 128);<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeRight].LineStyle = LineStyleType.Thin;<br />
            sheet.Range[&quot;B2:C5&quot;].Style.NumberFormat = &quot;\&quot;$\&quot;#,##0&quot;;<br />
        }<br />
[/csharp]</p>
<p>And we will use the preceding function for viewing our chart created.</p>
<p>[csharp]<br />
private void ExcelDocViewer(string fileName)<br />
        {<br />
            try<br />
            {<br />
                System.Diagnostics.Process.Start(fileName);<br />
            }<br />
            catch { }<br />
        }<br />
[/csharp]</p>
<p>Now it is time to run our program. You will see the output as follows.</p>
<p><div id="attachment_9071" style="width: 310px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Excel_Bar_Chart.png"><img decoding="async" aria-describedby="caption-attachment-9071" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Excel_Bar_Chart.png" alt="Excel Bar Chart" width="300" height="300" class="size-full wp-image-9071" srcset="/wp-content/uploads/2015/08/Excel_Bar_Chart.png 300w, /wp-content/uploads/2015/08/Excel_Bar_Chart-150x150.png 150w, /wp-content/uploads/2015/08/Excel_Bar_Chart-130x130.png 130w" sizes="(max-width: 300px) 100vw, 300px" /></a><p id="caption-attachment-9071" class="wp-caption-text">Excel Bar Chart</p></div></p>
<p><div id="attachment_9081" style="width: 669px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Excel_Bar_Chart_Output.png"><img decoding="async" aria-describedby="caption-attachment-9081" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Excel_Bar_Chart_Output.png" alt="Excel Bar Chart " width="659" height="458" class="size-full wp-image-9081" srcset="/wp-content/uploads/2015/08/Excel_Bar_Chart_Output.png 659w, /wp-content/uploads/2015/08/Excel_Bar_Chart_Output-300x208.png 300w, /wp-content/uploads/2015/08/Excel_Bar_Chart_Output-160x110.png 160w, /wp-content/uploads/2015/08/Excel_Bar_Chart_Output-400x278.png 400w" sizes="(max-width: 659px) 100vw, 659px" /></a><p id="caption-attachment-9081" class="wp-caption-text">Excel Bar Chart</p></div></p>
<p>As you can see it is very easy to give styles and border to our chart.</p>
<p>[csharp]<br />
//Style<br />
            sheet.Range[&quot;A1:C1&quot;].Style.Font.IsBold = true;<br />
            sheet.Range[&quot;A2:C2&quot;].Style.KnownColor = ExcelColors.LightYellow;<br />
            sheet.Range[&quot;A3:C3&quot;].Style.KnownColor = ExcelColors.LightGreen1;<br />
            sheet.Range[&quot;A4:C4&quot;].Style.KnownColor = ExcelColors.LightOrange;<br />
            sheet.Range[&quot;A5:C5&quot;].Style.KnownColor = ExcelColors.LightTurquoise;<br />
            //Border<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeTop].Color = Color.FromArgb(0, 0, 128);<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeTop].LineStyle = LineStyleType.Thin;<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeBottom].Color = Color.FromArgb(0, 0, 128);<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeBottom].LineStyle = LineStyleType.Thin;<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeLeft].Color = Color.FromArgb(0, 0, 128);<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeLeft].LineStyle = LineStyleType.Thin;<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeRight].Color = Color.FromArgb(0, 0, 128);<br />
            sheet.Range[&quot;A1:C5&quot;].Style.Borders[BordersLineType.EdgeRight].LineStyle = LineStyleType.Thin;<br />
            sheet.Range[&quot;B2:C5&quot;].Style.NumberFormat = &quot;\&quot;$\&quot;#,##0&quot;;<br />
[/csharp]</p>
<p>Like this we can crate Line Chart, Radar Chart and many more. Please try those too. Now we will see How to Save Excel Charts as Images.</p>
<p><strong>How to Save Excel Charts as Images</strong></p>
<p>Create another button and write the preceding codes in button click.</p>
<p>[csharp]<br />
private void button2_Click(object sender, EventArgs e)<br />
        {<br />
            Workbook workbook = new Workbook();<br />
            workbook.LoadFromFile(&quot;D:\\Sample.xlsx&quot;, ExcelVersion.Version2010);<br />
            Worksheet sheet = workbook.Worksheets[0];<br />
            Image[] imgs = workbook.SaveChartAsImage(sheet);<br />
            for (int i = 0; i &lt; imgs.Length; i++)<br />
            {<br />
                imgs[i].Save(string.Format(&quot;img-{0}.png&quot;, i), System.Drawing.Imaging.ImageFormat.Png);<br />
            }</p>
<p>        }<br />
[/csharp]</p>
<p>Here we are taking a file called Sample.xlsx and loop through the charts inside the file and save those as images with few lines codes. Sounds good right?</p>
<p><strong>VB.Net Code</strong><br />
[vb]<br />
Dim workbook As New Workbook()<br />
workbook.LoadFromFile(&quot;D:\\Sample.xlsx&quot;, ExcelVersion.Version2010)<br />
Dim sheet As Worksheet = workbook.Worksheets(0)<br />
Dim imgs As Image() = workbook.SaveChartAsImage(sheet)<br />
For i As Integer = 0 To imgs.Length &#8211; 1<br />
    imgs(i).Save(String.Format(&quot;img-{0}.png&quot;, i), ImageFormat.Png)<br />
Next<br />
[/vb]</p>
<p><strong>Conclusion</strong></p>
<p>I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/working-with-charts-using-spire-xls/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Find Occurrence Of A String</title>
		<link>https://sibeeshpassion.com/find-occurrence-of-a-string/</link>
					<comments>https://sibeeshpassion.com/find-occurrence-of-a-string/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Wed, 05 Aug 2015 00:53:48 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[C-Sharp Functions]]></category>
		<category><![CDATA[Find Occurrence of String]]></category>
		<category><![CDATA[Find String Form String]]></category>
		<category><![CDATA[Regex]]></category>
		<category><![CDATA[String Contains Substring]]></category>
		<category><![CDATA[Substring]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=7571</guid>

					<description><![CDATA[In this article you will learn the ways to find the occurrence of a string from a string, or find a sub string from a string. We are using C# language to do this demo. In times, you may have faced this requirement. And I am sure you would do that. This article is for the one who don&#8217;t know how to achieve this. We will be discussing two methods here. I hope you will like it. See demo Occurrence Of A String Demo Background Today I have got a requirement of creating a function which performs some operations according [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this article you will learn the ways to find the occurrence of a string from a string, or find a sub string from a string. We are using C# language to do this demo. In times, you may have faced this requirement. And I am sure you would do that. This article is for the one who don&#8217;t know how to achieve this. We will be discussing two methods here. I hope you will like it.</p>
<p><span style="color: #ff6600;"><strong>See demo</strong></span></p>
<p><a href="http://sibeeshpassion.com/demo/OccurrenceOfString/" target="_blank" rel="noopener">Occurrence Of A String Demo</a></p>
<p><span style="color: #ff6600;"><strong>Background</strong></span></p>
<p>Today I have got a requirement of creating a function which performs some operations according to the occurrence of a string in a given string. Like, if a string pattern contains more that one time in a given string, it must do some actions and if it is just one time it should do other actions. I have done this in two ways, here I am sharing you that. I hope some one may find it is useful.</p>
<p><span style="color: #ff6600;"><strong>Using the code</strong></span></p>
<p>We are going to discuss the following two ways to achieve this requirement.</p>
<li>Using Regex Class</li>
<li>Using Custom Function</li>
<p>We will start with a Regex class first.</p>
<p>To start with Regex, you need to add another namespace as given below.</p>
<p>[csharp]<br />
using System.Text.RegularExpressions;<br />
[/csharp]</p>
<p>Now consider we have designed our page as follows.</p>
<p>[html]<br />
&lt;div&gt;<br />
            &lt;table &gt;<br />
                &lt;tr&gt;<br />
                    &lt;td&gt;<br />
                        &lt;asp:Label ID=&quot;lblInputString&quot; runat=&quot;server&quot; Text=&quot;Input String&quot;&gt;&lt;/asp:Label&gt;<br />
                    &lt;/td&gt;<br />
                    &lt;td&gt;<br />
                        &lt;textarea id=&quot;txtInputString&quot; runat=&quot;server&quot;&gt;&lt;/textarea&gt;<br />
                    &lt;/td&gt;<br />
                &lt;/tr&gt;<br />
                &lt;tr&gt;<br />
                    &lt;td&gt;<br />
                        &lt;asp:Label ID=&quot;lblPattern&quot; runat=&quot;server&quot; Text=&quot;Pattern String&quot;&gt;&lt;/asp:Label&gt;<br />
                    &lt;/td&gt;<br />
                    &lt;td&gt;<br />
                        &lt;textarea id=&quot;txtPattern&quot; runat=&quot;server&quot;&gt;&lt;/textarea&gt;<br />
                    &lt;/td&gt;<br />
                &lt;/tr&gt;<br />
                &lt;tr&gt;<br />
                    &lt;td colspan=&quot;2&quot;&gt;<br />
                        &lt;asp:Button ID=&quot;btnCheckOccurance&quot; runat=&quot;server&quot; Text=&quot;Check Occurance&quot; OnClick=&quot;btnCheckOccurance_Click&quot; /&gt;<br />
                    &lt;/td&gt;<br />
                &lt;/tr&gt;<br />
                &lt;tr&gt;<br />
                    &lt;td colspan=&quot;2&quot;&gt;<br />
                        &lt;asp:Label ID=&quot;lblOutput&quot; runat=&quot;server&quot; Text=&quot;See Output Here!!! &lt;i&gt; Thank you for visiting. Please Visit Again!!! &lt;/i&gt;&quot;&gt;&lt;/asp:Label&gt;<br />
                    &lt;/td&gt;<br />
                &lt;/tr&gt;<br />
            &lt;/table&gt;<br />
        &lt;/div&gt;<br />
[/html]</p>
<p>And Some CSS styles as follows.</p>
<p>[css]<br />
&lt;style type=&quot;text/css&quot;&gt;<br />
        textarea {<br />
            width: 630px;<br />
            height: 100px;<br />
        }</p>
<p>        table {<br />
            border: 1px solid #ccc;<br />
            padding: 10px;<br />
            width: 800px;<br />
            text-align:center;<br />
        }</p>
<p>        tr {<br />
            border: 1px solid #999;<br />
            border-radius: 5px;<br />
        }</p>
<p>        td {<br />
            border: 1px solid #999;<br />
            padding: 10px;<br />
            border-radius: 5px;<br />
        }<br />
    &lt;/style&gt;<br />
[/css]</p>
<p>If you add the above codes and CSS, your page may looks like in the preceding image.</p>
<p><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/07/Find_Occurrence_Of_A_String_1.png" alt="" /></p>
<p>Now we will see our C# code. Please add the below lines of codes in the button click event.</p>
<p>[csharp]<br />
protected void btnCheckOccurance_Click(object sender, EventArgs e)<br />
    {<br />
        int occuranceCount = 0;</p>
<p>        //Checking Occurance<br />
        occuranceCount = Regex.Matches(txtInputString.Value.ToLower().Trim(), txtPattern.Value.ToLower().Trim()).Count;<br />
        if (occuranceCount &gt; 0)<br />
            lblOutput.Text = &quot;&lt;br/&gt;&lt;br/&gt;&lt;b&gt;Sibeesh Passion &lt;/b&gt;Says &lt;br/&gt;&lt;br/&gt;The given string pattern &lt;i&gt;&quot; + txtPattern.Value + &quot;&lt;/i&gt; Contains &quot; + occuranceCount + &quot; times in  &lt;i&gt;&quot;<br />
                + txtInputString.Value + &quot;&lt;/i&gt;&lt;br/&gt;&lt;br/&gt; Thank you for visiting. Please Visit Again!!!&quot;;<br />
        else<br />
            lblOutput.Text = &quot;&lt;br/&gt;&lt;br/&gt;&lt;b&gt;Sibeesh Passion &lt;/b&gt;Says &lt;br/&gt;&lt;br/&gt;The given string pattern &lt;i&gt;&quot; + txtPattern.Value + &quot;&lt;/i&gt; Is not occured s in  &lt;i&gt;&quot;<br />
                + txtInputString.Value + &quot;&lt;/i&gt;&lt;br/&gt;&lt;br/&gt; Thank you for visiting. Please Visit Again!!!&quot;;<br />
        //End<br />
    }<br />
[/csharp]</p>
<p>In the above code, we are finding the occurrence of a string by using a <em>Regex.Matches</em> function. The <em>Regex.Matches</em> function expects two parameters. </p>
<li>Input String (In which string we need to search for a string)</li>
<li>Pattern String(What we need to search in a string)</li>
<p>We are getting those two values from our texarea and pass as follows.</p>
<p>[csharp]<br />
Regex.Matches(txtInputString.Value.ToLower().Trim(), txtPattern.Value.ToLower().Trim()).Count;<br />
[/csharp]</p>
<p>Now if you run application, you will get output as follows.</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/07/Find_Occurrence_Of_A_String_Using_Regex.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/07/Find_Occurrence_Of_A_String_Using_Regex-300x185.png" alt="Find_Occurrence_Of_A_String_Using_Regex" width="300" height="185" class="alignnone size-medium wp-image-7611" srcset="/wp-content/uploads/2015/07/Find_Occurrence_Of_A_String_Using_Regex-300x185.png 300w, /wp-content/uploads/2015/07/Find_Occurrence_Of_A_String_Using_Regex-768x474.png 768w, /wp-content/uploads/2015/07/Find_Occurrence_Of_A_String_Using_Regex-400x247.png 400w, /wp-content/uploads/2015/07/Find_Occurrence_Of_A_String_Using_Regex.png 813w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/07/Find_Occurrence_Of_A_String_Using_Regex_2-e1437475061191.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/07/Find_Occurrence_Of_A_String_Using_Regex_2-300x183.png" alt="Find_Occurrence_Of_A_String_Using_Regex_2" width="300" height="183" class="alignnone size-medium wp-image-7621" /></a></p>
<p>As you can see I have given the words, &#8220;Sibeesh&#8221; and &#8220;passion&#8221; for testing, and it gave the correct number of occurrence right?</p>
<p>Now we will see how we can do this by Using a Custom Function.</p>
<p>Following in our function call.</p>
<p>[csharp]<br />
occuranceCount = FindOccurrences(txtInputString.Value.ToLower().Trim(), txtPattern.Value.ToLower().Trim());<br />
[/csharp]</p>
<p>And please find the function body below.</p>
<p>[csharp]<br />
 #region FindOccurrences<br />
    /// &lt;summary&gt;<br />
    /// This method is used to get the Count of Occurrences of a string in a string<br />
    /// &lt;/summary&gt;<br />
    /// &lt;param name=&quot;InputString&quot;&gt;&lt;/param&gt;<br />
    /// &lt;param name=&quot;patternString&quot;&gt;&lt;/param&gt;<br />
    /// &lt;returns&gt;Int&lt;/returns&gt;<br />
    public int FindOccurrences(string InputString, string patternString)<br />
    {<br />
        // Here we are looping through InputString<br />
        int intCount = 0;<br />
        int i = 0;<br />
        while ((i = InputString.IndexOf(patternString, i)) != -1)<br />
        {<br />
            i += patternString.Length;<br />
            intCount++;<br />
        }<br />
        return intCount;<br />
    }<br />
    #endregion<br />
[/csharp]</p>
<p>Now if your run you will get the same output as we got by using a Regex function.</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/07/Find_Occurrence_Of_A_String_Using_Custom_Function-e1437475554507.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/07/Find_Occurrence_Of_A_String_Using_Custom_Function-300x184.png" alt="Find_Occurrence_Of_A_String_Using_Custom_Function" width="300" height="184" class="alignnone size-medium wp-image-7631" /></a></p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/07/Find_Occurrence_Of_A_String_Using_Custom_Function_2-e1437475574384.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/07/Find_Occurrence_Of_A_String_Using_Custom_Function_2-300x184.png" alt="Find_Occurrence_Of_A_String_Using_Custom_Function_2" width="300" height="184" class="alignnone size-medium wp-image-7641" /></a></p>
<p>Now we will see our complete codes.</p>
<p><strong>Complete Code</strong></p>
<p><em>Default.aspx.cs</em></p>
<p>[csharp]<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text.RegularExpressions;<br />
using System.Web;<br />
using System.Web.UI;<br />
using System.Web.UI.WebControls;</p>
<p>public partial class _Default : System.Web.UI.Page<br />
{<br />
    protected void Page_Load(object sender, EventArgs e)<br />
    {</p>
<p>    }<br />
    protected void btnCheckOccurance_Click(object sender, EventArgs e)<br />
    {<br />
        int occuranceCount = 0;</p>
<p>        //Checking Occurance<br />
        //occuranceCount = Regex.Matches(txtInputString.Value.ToLower().Trim(), txtPattern.Value.ToLower().Trim()).Count;<br />
        occuranceCount = FindOccurrences(txtInputString.Value.ToLower().Trim(), txtPattern.Value.ToLower().Trim());<br />
        if (occuranceCount &gt; 0)<br />
            lblOutput.Text = &quot;&lt;br/&gt;&lt;br/&gt;&lt;b&gt;Sibeesh Passion &lt;/b&gt;Says &lt;br/&gt;&lt;br/&gt;The given string pattern &lt;i&gt;&quot; + txtPattern.Value + &quot;&lt;/i&gt; Contains &quot; + occuranceCount + &quot; times in  &lt;i&gt;&quot;<br />
                + txtInputString.Value + &quot;&lt;/i&gt;&lt;br/&gt;&lt;br/&gt; Thank you for visiting. Please Visit Again!!!&quot;;<br />
        else<br />
            lblOutput.Text = &quot;&lt;br/&gt;&lt;br/&gt;&lt;b&gt;Sibeesh Passion &lt;/b&gt;Says &lt;br/&gt;&lt;br/&gt;The given string pattern &lt;i&gt;&quot; + txtPattern.Value + &quot;&lt;/i&gt; Is not occured s in  &lt;i&gt;&quot;<br />
                + txtInputString.Value + &quot;&lt;/i&gt;&lt;br/&gt;&lt;br/&gt; Thank you for visiting. Please Visit Again!!!&quot;;<br />
        //End<br />
    }<br />
    #region FindOccurrences<br />
    /// &lt;summary&gt;<br />
    /// This method is used to get the Count of Occurrences of a string in a string<br />
    /// &lt;/summary&gt;<br />
    /// &lt;param name=&quot;InputString&quot;&gt;&lt;/param&gt;<br />
    /// &lt;param name=&quot;patternString&quot;&gt;&lt;/param&gt;<br />
    /// &lt;returns&gt;Int&lt;/returns&gt;<br />
    public int FindOccurrences(string InputString, string patternString)<br />
    {<br />
        // Here we are looping through InputString<br />
        int intCount = 0;<br />
        int i = 0;<br />
        while ((i = InputString.IndexOf(patternString, i)) != -1)<br />
        {<br />
            i += patternString.Length;<br />
            intCount++;<br />
        }<br />
        return intCount;<br />
    }<br />
    #endregion<br />
}<br />
[/csharp]</p>
<p><em>Default.aspx</em></p>
<p>[html]<br />
&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeFile=&quot;Default.aspx.cs&quot; Inherits=&quot;_Default&quot; %&gt;</p>
<p>&lt;!DOCTYPE html&gt;</p>
<p>&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;<br />
&lt;head runat=&quot;server&quot;&gt;<br />
    &lt;title&gt;Find Occurrence of String,Find String Form String,Regex,String Contains Substring &#8211; Sibeesh Passion&lt;/title&gt;<br />
    &lt;style type=&quot;text/css&quot;&gt;<br />
        textarea {<br />
            width: 630px;<br />
            height: 100px;<br />
        }</p>
<p>        table {<br />
            border: 1px solid #ccc;<br />
            padding: 10px;<br />
            width: 800px;<br />
            text-align:center;<br />
        }</p>
<p>        tr {<br />
            border: 1px solid #999;<br />
            border-radius: 5px;<br />
        }</p>
<p>        td {<br />
            border: 1px solid #999;<br />
            padding: 10px;<br />
            border-radius: 5px;<br />
        }<br />
    &lt;/style&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
    &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;<br />
        &lt;div&gt;<br />
            &lt;table &gt;<br />
                &lt;tr&gt;<br />
                    &lt;td&gt;<br />
                        &lt;asp:Label ID=&quot;lblInputString&quot; runat=&quot;server&quot; Text=&quot;Input String&quot;&gt;&lt;/asp:Label&gt;<br />
                    &lt;/td&gt;<br />
                    &lt;td&gt;<br />
                        &lt;textarea id=&quot;txtInputString&quot; runat=&quot;server&quot;&gt;&lt;/textarea&gt;<br />
                    &lt;/td&gt;<br />
                &lt;/tr&gt;<br />
                &lt;tr&gt;<br />
                    &lt;td&gt;<br />
                        &lt;asp:Label ID=&quot;lblPattern&quot; runat=&quot;server&quot; Text=&quot;Pattern String&quot;&gt;&lt;/asp:Label&gt;<br />
                    &lt;/td&gt;<br />
                    &lt;td&gt;<br />
                        &lt;textarea id=&quot;txtPattern&quot; runat=&quot;server&quot;&gt;&lt;/textarea&gt;<br />
                    &lt;/td&gt;<br />
                &lt;/tr&gt;<br />
                &lt;tr&gt;<br />
                    &lt;td colspan=&quot;2&quot;&gt;<br />
                        &lt;asp:Button ID=&quot;btnCheckOccurance&quot; runat=&quot;server&quot; Text=&quot;Check Occurance&quot; OnClick=&quot;btnCheckOccurance_Click&quot; /&gt;<br />
                    &lt;/td&gt;<br />
                &lt;/tr&gt;<br />
                &lt;tr&gt;<br />
                    &lt;td colspan=&quot;2&quot;&gt;<br />
                        &lt;asp:Label ID=&quot;lblOutput&quot; runat=&quot;server&quot; Text=&quot;See Output Here!!! &lt;i&gt; Thank you for visiting. Please Visit Again!!! &lt;/i&gt;&quot;&gt;&lt;/asp:Label&gt;<br />
                    &lt;/td&gt;<br />
                &lt;/tr&gt;<br />
            &lt;/table&gt;<br />
        &lt;/div&gt;<br />
    &lt;/form&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
[/html]</p>
<p><strong>Validation</strong></p>
<p>Now if you want you can add some basic validation to your code in server side and client side. I will always recommend you to do both validation.</p>
<p><em>Server Side</em><br />
[csharp]<br />
if (txtInputString.Value.ToLower().Trim() != &quot;&quot; &amp;&amp; txtPattern.Value.ToLower().Trim() != &quot;&quot;)<br />
        {<br />
}<br />
[/csharp]</p>
<p>Place the button click event code inside of this if condition.</p>
<p><em>Client Side</em></p>
<p><em>Add a Jquery reference </em></p>
<p>[js]<br />
&lt;script src=&quot;jquery-2.0.2.min.js&quot;&gt;&lt;/script&gt;<br />
[/js]</p>
<p>And add the below scripts.</p>
<p>[js]<br />
&lt;script&gt;<br />
        $(document).ready(function () {<br />
            $(&#8216;#btnCheckOccurance&#8217;).click(function () {<br />
                if ($(&#8216;#txtInputString&#8217;).val() == &quot;&quot; || $(&#8216;#txtPattern&#8217;).val() == &quot;&quot;) {<br />
                    alert(&#8216;Values can not be empty&#8217;);<br />
                    return false;<br />
                }<br />
            });<br />
        });<br />
    &lt;/script&gt;<br />
[/js]</p>
<p><span style="color: #ff6600;"><strong>Conclusion</strong></span></p>
<p>I hope someone found this article useful. Please share me your valuable thoughts and comments. Your feedback is always welcomed.</p>
<p>Thanks in advance. Happy coding!</p>
<p>Kindest Regards<br />
<a href="https://plus.google.com/+sibeeshkv" target="_blank" rel="noopener">Sibeesh Venu</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/find-occurrence-of-a-string/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Using Spire.XLS</title>
		<link>https://sibeeshpassion.com/using-spire-xls/</link>
					<comments>https://sibeeshpassion.com/using-spire-xls/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Sun, 12 Jul 2015 08:34:08 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Products]]></category>
		<category><![CDATA[Spire.XLS]]></category>
		<category><![CDATA[Convert Excel to PDF]]></category>
		<category><![CDATA[Convert Excel to PDF in C#]]></category>
		<category><![CDATA[Convert Excel to PDF in CSharp]]></category>
		<category><![CDATA[Excel to HTML]]></category>
		<category><![CDATA[Spire.Office]]></category>
		<category><![CDATA[Spire.XLs]]></category>
		<category><![CDATA[Using Spire.XLS]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=6731</guid>

					<description><![CDATA[[toc] Introduction Hi I hope you all are fine. Today we are going to see a new product Spire.XLS which helps us to create, manipulate, convert EXCEL file to other formats and many more. This product has been introduced by the company E-Iceblue. I hope you have read my article of Spire.Doc. If you have not read it, I recommend you to read it here: Using Spire.Doc Download source code Using Spire XLS With Visual Studio Background Always, managing excel files through code is a tough job for me. If you are also thinking the same, I h3ly recommend this [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[toc]</p>
<h3>Introduction</h3>
<p>Hi I hope you all are fine. Today we are going to see a new product <em>Spire.XLS</em> which helps us to create, manipulate, convert EXCEL file to other formats and many more. This product has been introduced by the company <a href="http://www.e-iceblue.com/" target="_blank" rel="noopener">E-Iceblue</a>. I hope you have read my article of <em>Spire.Doc</em>. If you have not read it, I recommend you to read it here: <a href="http://sibeeshpassion.com/using-spire-doc-introduction/" target="_blank" rel="noopener">Using Spire.Doc</a></p>
<h3>Download source code </h3>
<li><a href="https://code.msdn.microsoft.com/Using-SpireXLS-With-Visual-00c1d812" target="_blank" rel="noopener">Using Spire XLS With Visual Studio</a></li>
<h3>Background</h3>
<p>Always, managing excel files through code is a tough job for me. If you are also thinking the same, I h3ly recommend this product Spire.XLX from E-Iceblue. It made the task easier than ever. In this article I will show you the demo for converting the Excel files to other formats. I hope you will like it.</p>
<h3>Download the files</h3>
<p>You can always the needed files from here: <a href="http://www.e-iceblue.com/Download/download-excel-for-net-now.html" target="_blank" rel="noopener">Download Spire.XLS</a></p>
<h3>Install Spire.XLS</h3>
<p>I am using evaluation version with one month temporary license. There are free versions also available for spire.xls with some limitation. You can try that. Now click on the exe file after you extract the downloaded file. The installation will get started then.</p>
<p><img decoding="async" src="http://sibeeshpassion.com/content/images/InstallSpireXls.png" width="513" height="405" class="alignnone size-full" /></p>
<p>So Shall we start?</p>
<p>Once you Installed, you are ready to go. We will start with a “Simple Windows Form ” Application. Before getting started, Please install Spire.XLs and Visual studio 2008 or above. I am using Visual Studio 2015 RC. I hope everything set ?</p>
<p>Open your Visual Studio, click on New->Project->Select Visual C# (if you are good in C# or select Visual Basic) Project->Windows->Windows forms application->Name your project(I am naming it as Using SpireXLs)</p>
<p><img decoding="async" src="http://sibeeshpassion.com/content/images/UsingSpireXLS1.png" alt="Using Spire XLS" /></p>
<p>Now create a group box and a button in your form and name them :). Later, click on the button. </p>
<p><img decoding="async" src="http://sibeeshpassion.com/content/images/UsingSpireXLS2.png" alt="Using Spire XLS" /></p>
<p>Now right click on your project and click add reference, in the browse tab find out the folder in which you have installed spire xls. Usually it will be in the C:\Program Files\e-iceblue\Spire.Xls. Now just find your framework version from BIN folder and add Spire.xls.dll</p>
<p><img decoding="async" src="http://sibeeshpassion.com/content/images/UsingSpireXLS3.png" alt="Using Spire XLS" /></p>
<p><img decoding="async" src="http://sibeeshpassion.com/content/images/AddingSpireXLSReference.png" alt="Using Spire XLS" /></p>
<p>Now we have added reference too. So shall we start coding ?</p>
<h3>Using the code</h3>
<p>To start with coding you need to add the needed namespaces as follows.</p>
<p>[csharp]<br />
using Spire.Xls;<br />
using Spire.Pdf;<br />
using Spire.Xls.Converter;<br />
[/csharp]</p>
<p>In the button click event you need to add the following lines codes.</p>
<h4>C# Code</h4>
<p>[csharp]<br />
private void button1_Click(object sender, EventArgs e)<br />
        {<br />
             // load Excel file<br />
           Workbook workbook = new Workbook();<br />
           workbook.LoadFromFile(&quot;D:\\MyExcel.xlsx&quot;);<br />
           // Set PDF template<br />
           PdfDocument pdfDocument = new PdfDocument();<br />
           pdfDocument.PageSettings.Orientation = PdfPageOrientation.Landscape;<br />
           pdfDocument.PageSettings.Width = 970;<br />
           pdfDocument.PageSettings.Height = 850;<br />
           //Convert Excel to PDF using the template above<br />
           PdfConverter pdfConverter = new PdfConverter(workbook);<br />
           PdfConverterSettings settings = new PdfConverterSettings();<br />
           settings.TemplateDocument = pdfDocument;<br />
           pdfDocument = pdfConverter.Convert(settings);<br />
           // Save and preview PDF<br />
           pdfDocument.SaveToFile(&quot;MyPDF.pdf&quot;);<br />
           System.Diagnostics.Process.Start(&quot;MyPDF.pdf&quot;);</p>
<p>        }<br />
[/csharp]</p>
<h4>VB.NET Code</h4>
<p>[csharp]<br />
&#8216;load Excel file<br />
            Dim workbook As New Workbook()<br />
            workbook.LoadFromFile(&quot;D:\MyExcel.xlsx&quot;)<br />
            &#8216; Set PDF template<br />
            Dim pdfDocument As New PdfDocument()<br />
            pdfDocument.PageSettings.Orientation = PdfPageOrientation.Landscape<br />
            pdfDocument.PageSettings.Width = 970<br />
            pdfDocument.PageSettings.Height = 850<br />
            &#8216;Convert Excel to PDF using the template above<br />
            Dim pdfConverter As New PdfConverter(workbook)<br />
            Dim settings As New PdfConverterSettings()<br />
            settings.TemplateDocument = pdfDocument<br />
            pdfDocument = pdfConverter.Convert(settings)<br />
            &#8216; Save and preview PDF<br />
            pdfDocument.SaveToFile(&quot;MyPdf.pdf&quot;)<br />
            System.Diagnostics.Process.Start(&quot;MyPdf.pdf&quot;)<br />
[/csharp]</p>
<p>In the above lines code, we are loading an excel file MyExcel.xlsx from my drive. The following is the content of our excel file.</p>
<p><img decoding="async" src="http://sibeeshpassion.com/content/images/SpireXLSSampleExcelFile.png" alt="Using Spire XLS" /></p>
<p>Now if you run your project and click our button, you will get a pdf file as follows.</p>
<p><img decoding="async" src="http://sibeeshpassion.com/content/images/SpireXLSPDFConvertOutput.png" alt="Using Spire XLS" /></p>
<p>Cool!. Very simple right? Now we will go to other conversions as well.</p>
<h3>Excel to HTML</h3>
<p>To convert our excel file to HTML, you need to create a button in our form and paste the following codes to the button click event.</p>
<h4>C# Code</h4>
<p>[csharp]<br />
private void button2_Click(object sender, EventArgs e)<br />
        {<br />
            //load Excel file<br />
            Workbook workbook = new Workbook();<br />
            workbook.LoadFromFile(&quot;D:\\MyExcel.xlsx&quot;);<br />
            //convert Excel to HTML<br />
            Worksheet sheet = workbook.Worksheets[0];<br />
            sheet.SaveToHtml(&quot;MyHTML.html&quot;);<br />
            //Preview HTML<br />
            System.Diagnostics.Process.Start(&quot;MyHTML.html&quot;);</p>
<p>        }<br />
[/csharp]</p>
<h4>VB.NET Code</h4>
<p>[csharp]<br />
 Private Shared Sub Main(args As String())<br />
            &#8216;load Excel file<br />
            Dim workbook As New Workbook()<br />
            workbook.LoadFromFile(&quot;D:\\MyExcel.xlsx&quot;)<br />
            &#8216;convert Excel to HTML<br />
            Dim sheet As Worksheet = workbook.Worksheets(0)<br />
            sheet.SaveToHtml(&quot;MyHTML.html&quot;)<br />
            &#8216;Preview HTML<br />
            System.Diagnostics.Process.Start(&quot;MyHTML.html&quot;)<br />
        End Sub<br />
[/csharp]</p>
<p>Now if you run the code, you can see an html file as follows.</p>
<p><img decoding="async" src="http://sibeeshpassion.com/content/images/SpireXLsConvertHTMLPutput.png" alt="Using Spire XLS" /></p>
<h3>Excel To Image</h3>
<p>To convert our excel file to image, you need to create a button in our form and paste the following codes to the button click event.</p>
<h4>C# Code</h4>
<p>[csharp]<br />
private void button3_Click(object sender, EventArgs e)<br />
        {<br />
            Workbook workbook = new Workbook();<br />
            workbook.LoadFromFile(&quot;D:\\MyExcel.xlsx&quot;);<br />
            Worksheet sheet = workbook.Worksheets[0];<br />
            sheet.SaveToImage(&quot;MyImage.jpg&quot;);</p>
<p>        }<br />
[/csharp]</p>
<h4>VB.NET Code</h4>
<p>[csharp]<br />
  Shared Sub Main(ByVal args() As String)<br />
                     Dim workbook As New Workbook()<br />
                     workbook.LoadFromFile(&quot;D:\\MyExcel.xlsx&quot;)<br />
                     Dim sheet As Worksheet = workbook.Worksheets(0)<br />
                     sheet.SaveToImage(&quot;MyImage.jpg&quot;)<br />
  End Sub<br />
[/csharp]</p>
<p>Now if you run the code, you can see an Image as follows.</p>
<p><img decoding="async" src="http://sibeeshpassion.com/content/images/SpireXLSConvertExcelToImagesOutput1.png" alt="Using Spire XLS"/></p>
<p><img decoding="async" src="http://sibeeshpassion.com/content/images/SpireXLSConvertExcelToImagesOutput2.png" alt="Using Spire XLS"/></p>
<h3>Excel to CSV</h3>
<p>To convert our excel file to image, you need to create a button in our form and paste the following codes to the button click event.</p>
<h4>C# Code</h4>
<p>[csharp]<br />
private void button3_Click(object sender, EventArgs e)<br />
        {<br />
            Workbook workbook = new Workbook();<br />
            workbook.LoadFromFile(&quot;D:\\MyExcel.xlsx&quot;);<br />
            Worksheet sheet = workbook.Worksheets[0];<br />
            sheet.SaveToFile(&quot;MyCSV.csv&quot;, &quot;,&quot;, Encoding.UTF8);</p>
<p>        }<br />
[/csharp]</p>
<h4>VB.NET Code</h4>
<p>[csharp]<br />
  Shared Sub Main(ByVal args() As String)<br />
                     Dim workbook As New Workbook()<br />
                     workbook.LoadFromFile(&quot;D:\\MyExcel.xlsx&quot;)<br />
                     Dim sheet As Worksheet = workbook.Worksheets(0)<br />
                     sheet.SaveToFile(&quot;MyCSV.csv&quot;, &quot;,&quot;, Encoding.UTF8)</p>
<p>  End Sub<br />
[/csharp]</p>
<p>Now if you run the code, you can see a CSV file as follows.</p>
<p><img decoding="async" src="http://sibeeshpassion.com/content/images/SpireXLSConvertExcelToCSVOutput.png" alt="Using Spire XLS"/></p>
<p><em>Please be noted that, you can convert your excel to any other file format, there are plenty of options available. Please try that too. I have given only three options which I use always.</em></p>
<h3>Conclusion</h3>
<p>Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<h3>Your turn. What do you think?</h3>
<p>A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/using-spire-xls/feed/</wfw:commentRss>
			<slash:comments>9</slash:comments>
		
		
			</item>
		<item>
		<title>How to read RESX file in C#</title>
		<link>https://sibeeshpassion.com/how-to-read-resx-file-in-c-sharp/</link>
					<comments>https://sibeeshpassion.com/how-to-read-resx-file-in-c-sharp/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Mon, 06 Jul 2015 11:16:08 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Manipulate Resource file]]></category>
		<category><![CDATA[Read RESX File]]></category>
		<category><![CDATA[Resource File]]></category>
		<category><![CDATA[RESX]]></category>
		<category><![CDATA[RESX in C#]]></category>
		<category><![CDATA[Using resource file]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=6351</guid>

					<description><![CDATA[[toc] Introduction In this article, you will learn how we can read a RESX file in our application using c#. I hope you will like it. Download Source Code Please feel free to download the source code from here: Using RESX  Background A few days back I used a RESX file in my application and I have set some error codes and details in it. It worked like a charm. So I thought of sharing you a demo of how we can use RESX file in our application. What is RESX file? The .resx resource file format consists of XML entries [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[toc]</p>
<h2>Introduction</h2>
<p>In this article, you will learn how we can read a RESX file in our application using c#. I hope you will like it.</p>
<h2><strong>Download Source Code</strong></h2>
<p>Please feel free to download the source code from here: <a href="https://code.msdn.microsoft.com/How-to-read-RESX-file-in-C-3c967bca" target="_blank" rel="noopener">Using RESX </a></p>
<h2><strong>Background</strong></h2>
<p>A few days back I used a RESX file in my application and I have set some error codes and details in it. It worked like a charm. So I thought of sharing you a demo of how we can use RESX file in our application.</p>
<h3><strong>What is RESX file?</strong></h3>
<ul>
<li>The .resx resource file format consists of XML entries</li>
<li>These XML entries specify objects and strings inside XML tags</li>
<li>It can be easily manipulated</li>
</ul>
<h2><strong>Using the code</strong></h2>
<p>To start with, you need to create a web application. Here I am using Visual Studio 2012 and C# as the language.<br />
Once you created the application, you need to create a RESX file by clicking the &#8220;New Item&#8221;</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/07/UsingRESXFileinCSharp1.png"><img decoding="async" class="alignnone size-full wp-image-12680" src="http://sibeeshpassion.com/wp-content/uploads/2015/07/UsingRESXFileinCSharp1.png" alt="" width="594" height="663" srcset="/wp-content/uploads/2015/07/UsingRESXFileinCSharp1.png 594w, /wp-content/uploads/2015/07/UsingRESXFileinCSharp1-269x300.png 269w, /wp-content/uploads/2015/07/UsingRESXFileinCSharp1-400x446.png 400w, /wp-content/uploads/2015/07/UsingRESXFileinCSharp1-538x600.png 538w" sizes="(max-width: 594px) 100vw, 594px" /></a></p>
<p><img decoding="async" src="http://sibeeshpassion.com/Content/Images/UsingRESXFileinCSharp2.png" alt="" /></p>
<p>Now you can see a new file in your solution explorer named Resource1.resx</p>
<p><img decoding="async" src="http://sibeeshpassion.com/Content/Images/UsingRESXFileinCSharp3.png" alt="" /></p>
<p>So our RESX file is ready, right? Now we can set some values to that 🙂 You can see the values I set to my RESX file in the preceding image.</p>
<p><img decoding="async" src="http://sibeeshpassion.com/Content/Images/UsingRESXFileinCSharp4.png" alt="" /></p>
<p>Now add a web page and go to the code behind by right click+view code . What you need to do next is, adding needed namespaces. You can find out them from the preceding code block.</p>
<p>[csharp]<br />
using System.Reflection;<br />
using System.Resources;<br />
using System.Globalization;<br />
[/csharp]</p>
<p>Once it is done, you are ready to go. Please paste the below mentioned code in your page load.</p>
<p>[csharp]<br />
ResourceManager rm = new ResourceManager(&#8220;UsingRESX.Resource1&#8221;,<br />
Assembly.GetExecutingAssembly());<br />
String strWebsite = rm.GetString(&#8220;Website&#8221;,CultureInfo.CurrentCulture);<br />
String strName = rm.GetString(&#8220;Name&#8221;);<br />
form1.InnerText = &#8220;Website: &#8221; + strWebsite + &#8220;&#8211;Name: &#8221; + strName;<br />
[/csharp]</p>
<p>So in the above code block we are getting the values of &#8220;Name&#8221; and &#8220;Website&#8221; which we have already set in the RESX file. Cool right?</p>
<p>[csharp]<br />
ResourceManager rm = new ResourceManager(&#8220;UsingRESX.Resource1&#8221;,<br />
Assembly.GetExecutingAssembly());<br />
[/csharp]</p>
<p>In the above mentioned code block we are setting our Resource file to the ResourceManager class. Please be noted that in <em>UsingRESX.Resource1</em>, <em>UsingRESX</em> is my project base name and <em>Resource1</em> is my resource file name. The function <em>GetString</em> is used to read the resource file properties 🙂</p>
<h3>Output</h3>
<p>Now it is time to see the output.</p>
<p><img decoding="async" src="http://sibeeshpassion.com/Content/Images/UsingRESXFileinCSharp5.png" alt="" /></p>
<h2><strong>Conclusion</strong></h2>
<p>Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<h2><strong>Your turn. What do you think?</strong></h2>
<p>A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/how-to-read-resx-file-in-c-sharp/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to replace number from a string in C#</title>
		<link>https://sibeeshpassion.com/how-to-replace-number-from-a-string-in-csharp/</link>
					<comments>https://sibeeshpassion.com/how-to-replace-number-from-a-string-in-csharp/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Wed, 24 Jun 2015 09:32:10 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[C# functions]]></category>
		<category><![CDATA[C# Regex]]></category>
		<category><![CDATA[code snippet]]></category>
		<category><![CDATA[find number]]></category>
		<category><![CDATA[Regex]]></category>
		<category><![CDATA[Replace number]]></category>
		<category><![CDATA[replace number from string]]></category>
		<category><![CDATA[separate number and string]]></category>
		<category><![CDATA[Take number from string]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=5401</guid>

					<description><![CDATA[In this pose we will see how to replace a number from a string in C#. We can do this in several ways. Here I am going to show you one. I hope you will like this. Consider following is my string. [csharp] String myString = &#34;MyString1&#34;; [/csharp] And I need to take out the number 1 from the value MyString1. What will we do? To do this we can use Regex class in C#. Following is the code to achieve the same 🙂 [csharp] myString = Regex.Replace(sortdatafield, @&#34;[\d-]&#34;, string.Empty); [/csharp] Once you done and Run, you will get the [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this pose we will see how to replace a number from a string in C#. We can do this in several ways. Here I am going to show you one. I hope you will like this.</p>
<p>Consider following is my string.</p>
<p>[csharp]<br />
String myString = &quot;MyString1&quot;;<br />
[/csharp]</p>
<p>And I need to take out the number <em>1 </em>from the value <em>MyString1</em>. What will we do?</p>
<p>To do this we can use Regex class in C#. Following is the code to achieve the same 🙂</p>
<p>[csharp]<br />
myString = Regex.Replace(sortdatafield, @&quot;[\d-]&quot;, string.Empty);<br />
[/csharp]</p>
<p>Once you done and Run, you will get the new value  without numbers (<em>&#8220;MyString&#8221;</em>) in the variable <em>myString</em></p>
<p>I hope someone found this useful. Happy Coding 🙂</p>
<p>Kindly see my code snippets <a href="http://sibeeshpassion.com/category/code-snippets/" target="_blank" rel="noopener">here</a></p>
<p>Kindest Regards<br />
<a href="https://plus.google.com/+sibeeshkv" target="_blank" rel="noopener">Sibeesh Venu</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/how-to-replace-number-from-a-string-in-csharp/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to take numbers from a string in C#</title>
		<link>https://sibeeshpassion.com/how-to-take-numbers-from-a-string-in-csharp/</link>
					<comments>https://sibeeshpassion.com/how-to-take-numbers-from-a-string-in-csharp/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Wed, 24 Jun 2015 09:24:03 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[C# functions]]></category>
		<category><![CDATA[C# Regex]]></category>
		<category><![CDATA[code snippet]]></category>
		<category><![CDATA[find number]]></category>
		<category><![CDATA[Regex]]></category>
		<category><![CDATA[separate number and string]]></category>
		<category><![CDATA[Take number from string]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=5381</guid>

					<description><![CDATA[Consider following is my string. [csharp] String myString = &#34;MyString1&#34;; [/csharp] And I need to take out the number 1 from the value MyString1. What will we do? To do this we can use Regex class in C#. Following is the code to achieve the same 🙂 [csharp] myString = Regex.Match(myString , @&#34;\d+&#34;).Value; [/csharp] Once you done and Run, you will get value 1 in the variable myString I hope someone found this useful. Happy Coding 🙂 Kindest Regards Sibeesh Venu]]></description>
										<content:encoded><![CDATA[<p>Consider following is my string.<br />
[csharp]<br />
String myString = &quot;MyString1&quot;;<br />
[/csharp]</p>
<p>And I need to take out the number <em>1 </em>from the value <em>MyString1</em>. What will we do?</p>
<p>To do this we can use Regex class in C#. Following is the code to achieve the same 🙂</p>
<p>[csharp]<br />
myString = Regex.Match(myString , @&quot;\d+&quot;).Value;<br />
[/csharp]</p>
<p>Once you done and Run, you will get value <em>1</em> in the variable <em>myString </em></p>
<p>I hope someone found this useful. Happy Coding 🙂</p>
<p>Kindest Regards<br />
<a href="https://plus.google.com/+sibeeshkv" target="_blank" rel="noopener">Sibeesh Venu</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/how-to-take-numbers-from-a-string-in-csharp/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Split method with a string value in c#</title>
		<link>https://sibeeshpassion.com/split-method-with-a-string-value-in-c/</link>
					<comments>https://sibeeshpassion.com/split-method-with-a-string-value-in-c/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Sun, 31 May 2015 14:36:09 +0000</pubDate>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[C# SPlit]]></category>
		<guid isPermaLink="false">https://sibeeshpassion.com/?p=3811</guid>

					<description><![CDATA[As you know a normal split method is accepting only a character . It will throw an error when we give a string to split. This code shows you how you can use split method to split a string by a string in c#. [csharp] string myQuery=&#34;select * from tblAccount where id=1&#34; List&#60;string&#62; queryList = myQuery.Split(new string[] { &#34;where&#34; }, StringSplitOptions.None).ToList(); [/csharp] The queryList will give you the list after split Kindest Regards]]></description>
										<content:encoded><![CDATA[<p>As you know a normal split method is accepting only a character . It will throw an error when we give a string to split. This code shows you how you can use split method to split a string by a string in c#.<br />
[csharp]<br />
string myQuery=&quot;select * from tblAccount where id=1&quot;<br />
List&lt;string&gt; queryList = myQuery.Split(new string[] { &quot;where&quot; }, StringSplitOptions.None).ToList();<br />
[/csharp]<br />
The queryList  will give you the list after split</p>
<p>Kindest Regards</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/split-method-with-a-string-value-in-c/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
