<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Ishrar G]]></title><description><![CDATA[Ishrar G]]></description><link>https://blog.ishrar.in</link><generator>RSS for Node</generator><lastBuildDate>Mon, 16 Nov 2026 16:25:29 GMT</lastBuildDate><atom:link href="https://blog.ishrar.in/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Display Blog Articles in Blazor Site using GraphQL]]></title><description><![CDATA[This article demonstrates how to leverage Blazor for building with C#, to seamlessly integrate content from a headless CMS like Hashnode's GraphQL API]]></description><link>https://blog.ishrar.in/display-blog-articles-in-blazor-site-using-graphql</link><guid isPermaLink="true">https://blog.ishrar.in/display-blog-articles-in-blazor-site-using-graphql</guid><category><![CDATA[Hashnode]]></category><category><![CDATA[GraphQL]]></category><category><![CDATA[Blazor]]></category><category><![CDATA[dotnet]]></category><category><![CDATA[C#]]></category><category><![CDATA[.NET]]></category><category><![CDATA[APIs]]></category><category><![CDATA[components]]></category><category><![CDATA[Bootstrap]]></category><category><![CDATA[blazor server]]></category><category><![CDATA[HeadlessHashnode]]></category><dc:creator><![CDATA[Ishrar G]]></dc:creator><pubDate>Fri, 28 Jun 2024 13:49:50 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1719582621391/5fffb160-debc-45ee-9dec-e4009c3b7062.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In today's world of decoupled architectures, headless CMS systems provide a flexible and scalable approach to content management.</p>
<p>This article demonstrates how to leverage Blazor, a .NET framework for building interactive web UIs with C#, to seamlessly integrate content from a headless CMS like <a target="_blank" href="https://apidocs.hashnode.com/">Hashnode's GraphQL API</a> into your Blazor application.</p>
<p>I have <a target="_blank" href="https://ishrar.in">my site</a> in Blazor Server and I decided to show most recent articles from my <a target="_blank" href="https://blog.ishrar.in">blog</a> on my site. I did it successfully and it was really a fun. I wanted to share fun with you.</p>
<p>Let's begin...</p>
<p>Let's assume you already have Blazor site and Hashnode blog available with you.</p>
<p><strong>Prerequisites:</strong></p>
<ul>
<li><p>Basic understanding of Blazor development</p>
</li>
<li><p>A Hashnode blog with a few articles</p>
</li>
<li><p>A Blazor project set up (use Visual Studio or the .NET CLI)</p>
</li>
</ul>
<h3 id="heading-activate-hashnode-headless-feature"><strong>Activate Hashnode Headless feature</strong></h3>
<ul>
<li><p>Goto Blog Dashboard</p>
</li>
<li><p>Open Settings</p>
</li>
<li><p>Goto Domain</p>
</li>
<li><p>Select Hashnode Headless CMS</p>
</li>
<li><p>Enable headless mode</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719573657592/873faa97-30cd-4173-b5b2-2e510790a72d.png" alt class="image--center mx-auto" /></p>
<p>Lets Jump to our Blazor app.</p>
<h3 id="heading-install-nuget-packages"><strong>Install Nuget Packages :</strong></h3>
<p>Begin by installing the <code>System.Text.Json, Newtonsoft.Json</code> library in your Blazor project. You can also use <code>Apollo GraphQL Client</code> NuGet package. In this example I have not used it and I achieved with <code>httpclient</code></p>
<p>Bash</p>
<pre><code class="lang-bash">dotnet add package System.Text.Json
dotnet add package Newtonsoft.Json
</code></pre>
<p>Interface idea: We are going to display 9 most recent articles in 3 rows with 3 articles in each row.</p>
<p>Lets create a Article Model in <code>Article.cs</code></p>
<pre><code class="lang-csharp"> <span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Article</span>
 {
     <span class="hljs-keyword">public</span> <span class="hljs-keyword">string</span> Id { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
     <span class="hljs-keyword">public</span> <span class="hljs-keyword">string</span> Slug { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
     <span class="hljs-keyword">public</span> <span class="hljs-keyword">string</span> Title { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
     <span class="hljs-keyword">public</span> <span class="hljs-keyword">string</span> Url { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
     <span class="hljs-keyword">public</span> <span class="hljs-keyword">string</span> OgImage { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
 }
</code></pre>
<h3 id="heading-create-service-to-bring-articles-from-hashnode-blog-from-graphql-api">Create Service to Bring Articles from Hashnode Blog from GraphQL API</h3>
<p>Create one Service Class into <code>ArticleService.cs</code></p>
<pre><code class="lang-csharp"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">ArticleService</span>
{
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">readonly</span> HttpClient _httpClient;

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">ArticleService</span>(<span class="hljs-params">HttpClient httpClient</span>)</span>
    {
        _httpClient = httpClient;
    }

    <span class="hljs-keyword">public</span> <span class="hljs-keyword">async</span> Task&lt;List&lt;Article&gt;&gt; GetArticlesAsync()
    {
        <span class="hljs-keyword">string</span> blogAccountName = <span class="hljs-string">"yourblogaccountname"</span>;
        <span class="hljs-keyword">string</span> AuthenticationToken = <span class="hljs-string">"c85e054t-43c4-488b-9254-74c00b07c01e"</span>;

        <span class="hljs-keyword">var</span> query = <span class="hljs-keyword">new</span>
        {
            query = <span class="hljs-string">@"
            query GetUserFeed {
                user(username: """</span> + blogAccountName + <span class="hljs-string">@""") {
                    posts(pageSize: 9, page: 1) {
                        edges {
                            node {
                                id,
                                slug,
                                title,
                                url,
                                ogMetaData {
                                    image
                                }
                            }
                        }
                    }
                }
            }
        "</span>
        };

        <span class="hljs-keyword">var</span> content = <span class="hljs-keyword">new</span> StringContent(JsonSerializer.Serialize(query), Encoding.UTF8, <span class="hljs-string">"application/json"</span>);
        _httpClient.DefaultRequestHeaders.Authorization = <span class="hljs-keyword">new</span> AuthenticationHeaderValue(<span class="hljs-string">"Bearer"</span>, AuthenticationToken);
        <span class="hljs-keyword">var</span> response = <span class="hljs-keyword">await</span> _httpClient.PostAsync(<span class="hljs-string">"https://gql.hashnode.com/"</span>, content);

        response.EnsureSuccessStatusCode();
        <span class="hljs-keyword">var</span> responseContent = <span class="hljs-keyword">await</span> response.Content.ReadAsStringAsync();

        <span class="hljs-keyword">var</span> articles = <span class="hljs-keyword">new</span> List&lt;Article&gt;();

        <span class="hljs-keyword">var</span> json = JObject.Parse(responseContent);
        <span class="hljs-keyword">var</span> edges = json[<span class="hljs-string">"data"</span>][<span class="hljs-string">"user"</span>][<span class="hljs-string">"posts"</span>][<span class="hljs-string">"edges"</span>];

        <span class="hljs-keyword">foreach</span> (<span class="hljs-keyword">var</span> edge <span class="hljs-keyword">in</span> edges)
        {
            <span class="hljs-keyword">var</span> node = edge[<span class="hljs-string">"node"</span>];
            <span class="hljs-keyword">var</span> article = <span class="hljs-keyword">new</span> Article
            {
                Id = node[<span class="hljs-string">"id"</span>].ToString(),
                Slug = node[<span class="hljs-string">"slug"</span>].ToString(),
                Title = node[<span class="hljs-string">"title"</span>].ToString(),
                Url = node[<span class="hljs-string">"url"</span>].ToString(),
            };

            <span class="hljs-keyword">if</span> (node[<span class="hljs-string">"ogMetaData"</span>] != <span class="hljs-literal">null</span>)
            {
                <span class="hljs-keyword">var</span> og = node[<span class="hljs-string">"ogMetaData"</span>];
                article.OgImage = og[<span class="hljs-string">"image"</span>]?.ToString();
            }

            articles.Add(article);
        }

        <span class="hljs-keyword">return</span> articles;
    }
}
</code></pre>
<p>Above code prepares GraphQL query and sends request to Hashnode API service to return article's Id, Slug, Title, URL and article's OgImage. It returns the list of Articles.</p>
<h3 id="heading-get-authentication-token">Get Authentication Token</h3>
<p>If you do not have the Authentication token. It is easy to get one in Hashnode. You can jump to Developer section in Settings and click on Generate New Token</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1719575610277/484b0aef-6c2f-454c-9c19-947673f1bd51.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-add-service-to-dependency-injection">Add Service to Dependency Injection</h3>
<p>Now, Add service to the dependency injection container (in <code>Program.cs</code>). Specifically, it is registering an HTTP client for the ArticleService class.</p>
<pre><code class="lang-csharp">builder.Services.AddHttpClient&lt;ArticleService&gt;();
</code></pre>
<h3 id="heading-create-component-to-display-blog-articles">Create Component to Display Blog Articles</h3>
<p>Create Component Articles.razor to articles loaded by service</p>
<pre><code class="lang-csharp">@inject ArticleService ArticleService

&lt;p&gt;&lt;em&gt;Loading...&lt;/em&gt;&lt;/p&gt;

@if (articles != <span class="hljs-literal">null</span>)
{
  &lt;div <span class="hljs-keyword">class</span>=<span class="hljs-string">"row"</span>&gt;
    @foreach (<span class="hljs-keyword">var</span> article <span class="hljs-keyword">in</span> articles)
    {
      &lt;div <span class="hljs-keyword">class</span>=<span class="hljs-string">"col-md-4 mb-4"</span>&gt;
        &lt;div <span class="hljs-keyword">class</span>=<span class="hljs-string">"card"</span>&gt;
          @if (!<span class="hljs-keyword">string</span>.IsNullOrEmpty(article.OgImage))
          {
            &lt;img src=<span class="hljs-string">"@article.OgImage"</span> <span class="hljs-keyword">class</span>=<span class="hljs-string">"card-img-top"</span> alt=<span class="hljs-string">"@article.Title"</span> /&gt;
          }
          <span class="hljs-keyword">else</span>
          {
            &lt;img src=<span class="hljs-string">"images/Default.png"</span> <span class="hljs-keyword">class</span>=<span class="hljs-string">"card-img-top"</span> alt=<span class="hljs-string">"@article.Title"</span> /&gt;
          }
          &lt;div <span class="hljs-keyword">class</span>=<span class="hljs-string">"card-body"</span>&gt;
            &lt;a href=<span class="hljs-string">"@article.Url"</span> target=<span class="hljs-string">"_blank"</span>&gt;
              &lt;h5 <span class="hljs-keyword">class</span>=<span class="hljs-string">"card-title"</span>&gt;@article.Title&lt;/h5&gt;
            &lt;/a&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    }
  &lt;/div&gt;
}

@code {
  <span class="hljs-keyword">private</span> List&lt;Article&gt; articles;

  <span class="hljs-function"><span class="hljs-keyword">protected</span> <span class="hljs-keyword">override</span> <span class="hljs-keyword">async</span> Task <span class="hljs-title">OnInitializedAsync</span>(<span class="hljs-params"></span>)</span>
  {
    articles = <span class="hljs-keyword">await</span> ArticleService.GetArticlesAsync();
  }
}
</code></pre>
<p>Above component brings articles using ArticleService and display them in 3X3 using bootstrap css.</p>
<p>Make sure you have included latest bootstrap included in App.razor or Parent Layout of the page</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> /&gt;</span>
</code></pre>
<p>Finally place the Article.razor component wherever you want to display the articles from blog.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"mt-12 text-center gap-5"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text-3xl font-bold"</span>&gt;</span>Blog posts<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"articles"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">Articles</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">Articles</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>For more details you can refer these</p>
<ul>
<li><p><a target="_blank" href="https://gql.hashnode.com/">Hashnode API Playground</a></p>
</li>
<li><p><a target="_blank" href="https://apidocs.hashnode.com/">Hashnode Public API Docs</a></p>
</li>
<li><p><a target="_blank" href="https://www.c-sharpcorner.com/article/create-a-simple-blazor-server-application-with-net-core-3-0/">Create A Simple Blazor Server Application With .NET Core 3.0 (c-sharpcorner.com)</a></p>
</li>
<li><p><a target="_blank" href="https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/dependency-injection?view=aspnetcore-8.0">ASP.NET Core Blazor dependency injection | Microsoft Learn</a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[ChatGPT vs Stack Overflow]]></title><description><![CDATA[Every programmer faces roadblocks. When you're stuck on a bug or wrestling with a concept, it's natural to seek help. But with two powerful resources like…]]></description><link>https://blog.ishrar.in/chatgpt-vs-stack-overflow</link><guid isPermaLink="true">https://blog.ishrar.in/chatgpt-vs-stack-overflow</guid><category><![CDATA[chatgpt]]></category><category><![CDATA[Stack Overflow]]></category><category><![CDATA[AI]]></category><dc:creator><![CDATA[Ishrar G]]></dc:creator><pubDate>Sat, 06 Apr 2024 18:30:38 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1719586097552/c03265a4-eb00-499a-b0ea-7007e148cb37.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-choosing-your-weapon-in-the-coding-struggle">Choosing Your Weapon in the Coding Struggle</h2>
<p>Every programmer faces roadblocks. When you're stuck on a bug or wrestling with a concept, it's natural to seek help. But with two powerful resources like Stack Overflow and ChatGPT, which one should you reach for first? The answer, like most things in programming, depends on the nature of your obstacle. Let's break down their strengths to help you choose wisely.</p>
<p><strong>Stack Overflow: Your Community of Experts</strong></p>
<p>Stack Overflow thrives on its massive community of developers. It's a treasure trove of questions and answers on practically any programming hurdle imaginable. Here's when Stack Overflow shines:</p>
<ul>
<li><p><strong>Laser-Focused Solutions:</strong> Stuck with a specific error message? Stack Overflow likely has the answer. With countless users facing similar issues, there's a high chance someone has found a solution you can adapt.</p>
</li>
<li><p><strong>Deep Dives and Explanations:</strong> Complex problems often require a nuanced understanding. Stack Overflow's threaded discussions allow for in-depth explanations of solutions and alternative approaches, giving you a well-rounded grasp of the fix.</p>
</li>
<li><p><strong>Building Your Reputation:</strong> Actively contributing valuable answers and earning upvotes establishes you as a credible programmer within the community.</p>
</li>
</ul>
<p><strong>ChatGPT: The AI Sidekick for Creative Problem-Solving</strong></p>
<p>ChatGPT takes a different approach. This large language model utilizes AI to offer a unique kind of assistance:</p>
<ul>
<li><p><strong>Conceptual Clarity:</strong> Struggling with a theoretical programming concept? ChatGPT can break it down into simpler terms, aiding your fundamental understanding.</p>
</li>
<li><p><strong>Code Snippet Generation:</strong> Need a springboard to get started? While always requiring a verification step for accuracy, ChatGPT can generate basic code snippets to kickstart your coding process.</p>
</li>
<li><p><strong>Brainstorming Buddy:</strong> Facing a new kind of problem? Chatting with ChatGPT can spark fresh ideas and lead you down unexplored avenues for a solution.</p>
</li>
</ul>
<p><strong>The Programmer's Powerhouse: Combining Strengths</strong></p>
<p>The key to tackling coding roadblocks effectively lies in using Stack Overflow and ChatGPT strategically:</p>
<ul>
<li><p><strong>For specific errors or troubleshooting, leverage Stack Overflow's search functionality and community expertise.</strong></p>
</li>
<li><p><strong>When you need to grasp a concept or brainstorm creative solutions, utilize ChatGPT's ability to explain and generate ideas.</strong></p>
</li>
</ul>
<p>Remember, the best course of action often involves a tag-team approach. Stack Overflow equips you with the collective knowledge of experienced programmers, while ChatGPT acts as your AI brainstorming partner. The next time you're stuck, don't fret – equip yourself with the right tool for the job and conquer that coding challenge!</p>
]]></content:encoded></item><item><title><![CDATA[Picking the Perfect fit: Cosmos DB vs. SQL Server for your .NET Application]]></title><description><![CDATA[Building a .NET application? Choosing the right database is crucial. Two strong contenders are Azure Cosmos DB and SQL Server. But which one reigns supreme…]]></description><link>https://blog.ishrar.in/picking-the-perfect-fit-cosmos-db-vs-sql-server-for-your-net-application</link><guid isPermaLink="true">https://blog.ishrar.in/picking-the-perfect-fit-cosmos-db-vs-sql-server-for-your-net-application</guid><category><![CDATA[CosmosDB]]></category><category><![CDATA[SQL Server]]></category><category><![CDATA[Azure]]></category><category><![CDATA[dotnet]]></category><dc:creator><![CDATA[Ishrar G]]></dc:creator><pubDate>Wed, 03 Apr 2024 18:30:41 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1719586974997/bf93a61d-2262-4b68-b9c1-1788952a6e73.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Building a .NET application? Choosing the right database is crucial. Two strong contenders are Azure Cosmos DB and SQL Server. But which one reigns supreme for your project? Let's break it down:</p>
<p><strong>SQL Server: The Structured Star</strong></p>
<p>Shine bright with SQL Server if your data has a well-defined structure and complex relationships. This relational database excels at handling transactions and queries involving multiple tables. Ideal for:</p>
<ul>
<li><p>E-commerce applications with customer data and order history.</p>
</li>
<li><p>Inventory management systems with product details and stock levels.</p>
</li>
<li><p>Financial applications requiring strict data integrity and ACID compliance.</p>
</li>
</ul>
<p><strong>Cosmos DB: The Flexible Flyer</strong></p>
<p>Soar into the world of NoSQL with Cosmos DB! This globally distributed database thrives on unstructured or semi-structured data. It scales effortlessly and offers low latency for geographically dispersed users. Perfect for:</p>
<ul>
<li><p>Mobile apps that need offline data access and real-time sync.</p>
</li>
<li><p>IoT applications that collect and analyze sensor data streams.</p>
</li>
<li><p>Social media platforms that handle vast amounts of user-generated content.</p>
</li>
</ul>
<p><strong>The Verdict: It Depends</strong></p>
<p>The champion depends on your project's specific needs. Here's a quick cheat sheet:</p>
<ul>
<li><p><strong>Structured Data &amp; Complex Queries?</strong> - SQL Server.</p>
</li>
<li><p><strong>Unstructured Data &amp; Global Reach?</strong> - Cosmos DB.</p>
</li>
<li><p><strong>Budget Conscious?</strong> - SQL Server might be more cost-effective for smaller projects.</p>
</li>
</ul>
<p>Remember, you can also leverage both! Consider using Cosmos DB for frequently accessed, globally distributed data, while keeping historical data or data with strict relationships in SQL Server.</p>
]]></content:encoded></item><item><title><![CDATA[.NET 9: A Challenger Emerges for MediatR in Event Handling?]]></title><description><![CDATA[MediatR, a popular mediator library for .NET applications, might face a new contender in the event handling arena - .NET 9. While .NET 9 isn't designed…]]></description><link>https://blog.ishrar.in/net-9-a-challenger-emerges-for-mediatr-in-event-handling</link><guid isPermaLink="true">https://blog.ishrar.in/net-9-a-challenger-emerges-for-mediatr-in-event-handling</guid><category><![CDATA[MediatR]]></category><category><![CDATA[dotnet9]]></category><dc:creator><![CDATA[Ishrar G]]></dc:creator><pubDate>Fri, 29 Mar 2024 18:30:50 GMT</pubDate><content:encoded><![CDATA[<p>MediatR, a popular mediator library for .NET applications, might face a new contender in the event handling arena - .NET 9. While .NET 9 isn't designed solely for event handling, its built-in capabilities and developer focus could pose a challenge to MediatR's dominance.</p>
<p>Here's why .NET 9 could shake things up:</p>
<ul>
<li><p><strong>Minimal Boilerplate:</strong> .NET 9 introduces minimal boilerplate code for event handling. This can streamline development compared to MediatR, which often requires more code to define and handle events.</p>
</li>
<li><p><strong>Seamless Integration:</strong> Since .NET 9 comes from Microsoft, it integrates perfectly with other .NET technologies. This could be advantageous for developers already invested in the .NET ecosystem, reducing the need for external libraries like MediatR.</p>
</li>
<li><p><strong>Focus on Developers:</strong> .NET 9's emphasis on developer experience extends to event handling. Expect clear syntax and intuitive tools for managing events within your application.</p>
</li>
</ul>
<p>However, it's important to consider these points as well:</p>
<ul>
<li><p><strong>Maturity Matters:</strong> MediatR has a well-established community and a wealth of existing resources. .NET 9's event handling features are relatively new, and the developer ecosystem might take time to mature.</p>
</li>
<li><p><strong>Beyond .NET:</strong> If you're working with a mix of technologies beyond the .NET framework, MediatR might offer better flexibility due to its non-framework-specific nature.</p>
</li>
<li><p><strong>Learning Curve:</strong> Developers familiar with MediatR might need to adjust to .NET 9's approach to event handling.</p>
</li>
</ul>
<p>In conclusion, .NET 9 presents a compelling alternative for event handling within .NET projects. While it might not completely replace MediatR, it offers a streamlined and developer-friendly approach. The choice between the two will depend on your project's specific needs, team expertise, and existing technology stack.</p>
]]></content:encoded></item><item><title><![CDATA[.NET MVC: A Framework Through the Ages (From 4.5 to .NET 8)]]></title><description><![CDATA[The Model-View-Controller (MVC) design pattern remains a cornerstone of web development. But how has ASP.NET MVC, the .NET implementation of MVC, evolved…]]></description><link>https://blog.ishrar.in/net-mvc-a-framework-through-the-ages-from-45-to-net-8</link><guid isPermaLink="true">https://blog.ishrar.in/net-mvc-a-framework-through-the-ages-from-45-to-net-8</guid><category><![CDATA[mvc]]></category><category><![CDATA[.NET]]></category><category><![CDATA[#dotnet8]]></category><category><![CDATA[#DotNetFramework]]></category><dc:creator><![CDATA[Ishrar G]]></dc:creator><pubDate>Sun, 24 Mar 2024 18:30:43 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1719585401943/d16ae25d-256c-4738-9955-a77a2cf5b8ce.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The Model-View-Controller (MVC) design pattern remains a cornerstone of web development. But how has ASP.NET MVC, the .NET implementation of MVC, evolved over time? Let's take a trip down memory lane and explore the key differences between ASP.NET MVC in .NET Framework 4.5 and its modern iteration in .NET 8.</p>
<p><strong>The Veteran: ASP.NET MVC in .NET Framework 4.5 (circa 2012)</strong></p>
<p>Released in 2012, ASP.NET MVC 4.5 offered a robust framework for building web applications on Windows. Here's what defined this version:</p>
<ul>
<li><p><strong>C# Support:</strong> Limited to versions up to C# 7.3. This meant developers couldn't leverage features introduced in later C# versions, like pattern matching and async/await enhancements.</p>
</li>
<li><p><strong>Tight Windows Integration:</strong> Designed specifically for the .NET Framework, it wasn't well-suited for cross-platform development.</p>
</li>
<li><p><strong>Focus on Features:</strong> While feature-rich, it sometimes led to increased complexity for developers.</p>
</li>
</ul>
<p><strong>The Modern Marvel: ASP.NET MVC in .NET 8 (2023 and Beyond)</strong></p>
<p>.NET 8, released in late 2023, ushered in a new era for ASP.NET MVC. Here's what sets it apart:</p>
<ul>
<li><p><strong>C# Evolution:</strong> Full compatibility with the latest C# versions allows developers to utilize advanced language features for cleaner and more efficient code.</p>
</li>
<li><p><strong>Cross-Platform Prowess:</strong> .NET 8 embraces a cross-platform approach, enabling development for Windows, Linux, and macOS. This opens doors for broader application deployment options.</p>
</li>
<li><p><strong>Focus on Developer Experience:</strong> Streamlined features and improved tooling prioritize developer experience, making the development process faster and more intuitive.</p>
</li>
</ul>
<p><strong>Beyond the Differences: A Shared Legacy</strong></p>
<p>Despite these advancements, ASP.NET MVC in .NET 8 retains the core principles of its predecessor:</p>
<ul>
<li><p><strong>Separation of Concerns:</strong> MVC's core strength - clear separation between models, views, and controllers - remains intact. This promotes cleaner code organization and easier maintenance.</p>
</li>
<li><p><strong>Flexibility:</strong> Developers still enjoy the flexibility to customize their applications and integrate external libraries seamlessly.</p>
</li>
</ul>
<p><strong>Choosing Your Path: Legacy vs. Modern</strong></p>
<p>The choice between these versions depends on your project's needs:</p>
<ul>
<li><p><strong>Sticking with .NET Framework 4.5?</strong> ASP.NET MVC 4.5 remains a solid option for existing projects with established codebases.</p>
</li>
<li><p><strong>Embracing the Future?</strong> For new projects or those seeking cross-platform capabilities and the latest C# features, .NET 8 with its modern MVC implementation is the way to go.</p>
</li>
</ul>
<p>No matter which version you choose, ASP.NET MVC continues to be a powerful framework for building web applications. By understanding the evolution of this framework, developers can make informed decisions and leverage the latest advancements to create robust and efficient web experiences.</p>
]]></content:encoded></item><item><title><![CDATA[.NET 9: Get Ready for the Cloud-Powered Future]]></title><description><![CDATA[Calling all .NET developers! Buckle up because .NET 9 is on the horizon, bringing exciting innovations to your cloud-based development game. While…]]></description><link>https://blog.ishrar.in/net-9-get-ready-for-the-cloud-powered-future</link><guid isPermaLink="true">https://blog.ishrar.in/net-9-get-ready-for-the-cloud-powered-future</guid><category><![CDATA[dotnet9]]></category><category><![CDATA[dotnet]]></category><category><![CDATA[Azure]]></category><dc:creator><![CDATA[Ishrar G]]></dc:creator><pubDate>Fri, 22 Mar 2024 18:30:45 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1719585269460/f781a686-99a3-4656-ab57-f4d716b092ef.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Calling all .NET developers! Buckle up because .NET 9 is on the horizon, bringing exciting innovations to your cloud-based development game. While Microsoft hasn't locked in a specific release date, .NET 9 Preview 1 is already out, giving you a chance to tinker with the upcoming awesomeness.</p>
<p>So, what's the big deal about .NET 9? Here are some key highlights to get you pumped:</p>
<ul>
<li><p><strong>Cloud Native Champion:</strong> Ever dreamt of seamless cloud deployment? .NET 9 makes it a reality with tighter integration with Azure cloud services. This translates to a smoother workflow, especially for developers already using Microsoft Azure.</p>
</li>
<li><p><strong>Speed Demon Performance:</strong> Buckle up for faster applications! The upgraded 64-bit JIT compiler in .NET 9 promises significant performance enhancements. This means happier users and potentially shorter development cycles for you.</p>
</li>
<li><p><strong>Developer Productivity on Steroids:</strong> Tired of writing complex code for data processing? Say hello to LINQ's brand new CountBy and AggregateBy methods in .NET 9. These features streamline data processing, saving you time and effort. Plus, the System.Text.Json library gains new functionalities for easier JSON serialization, making data exchange a breeze.</p>
</li>
<li><p><strong>Collaboration is Key:</strong> Microsoft is all about fostering a collaborative environment. They're working closely with industry partners like Canonical and Red Hat to ensure .NET 9 integrates seamlessly across various environments.</p>
</li>
<li><p><strong>Just the Beginning:</strong> The .NET 9 Preview 1 is just a taste of what's to come. With its focus on cloud development and empowering developers, .NET 9 promises to be a game-changer. Keep your eyes peeled for further announcements and updates as we inch closer to the official release!</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Devin the AI: Partner, Not Replacement]]></title><description><![CDATA[Devin, the new AI software engineer, has sparked debate: will it replace human coders? Likely not. While Devin can churn out code efficiently, it lacks the…]]></description><link>https://blog.ishrar.in/devin-the-ai-partner-not-replacement</link><guid isPermaLink="true">https://blog.ishrar.in/devin-the-ai-partner-not-replacement</guid><category><![CDATA[DevIN]]></category><dc:creator><![CDATA[Ishrar G]]></dc:creator><pubDate>Wed, 20 Mar 2024 19:23:59 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1719585061841/7b49712e-3b11-4a5c-8d5a-db8b03afee8b.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Devin, the new AI software engineer, has sparked debate: will it replace human coders? Likely not. While Devin can churn out code efficiently, it lacks the creativity and problem-solving skills of a human engineer.</p>
<p>Imagine Devin as a tireless assistant programmer. It can write basic code, identify bugs, and optimize existing programs. This frees up human engineers for the complex tasks – designing new systems, tackling unique challenges, and collaborating with clients. The future of software development is likely a team effort, with Devin as a powerful tool in the hands of skilled human engineers.</p>
]]></content:encoded></item><item><title><![CDATA[How I Built a NuGet Package]]></title><description><![CDATA[Open-source software has always been a cornerstone of the programming world, providing a platform for innovation and collaboration. Despite being a firm…]]></description><link>https://blog.ishrar.in/how-i-built-a-nuget-package</link><guid isPermaLink="true">https://blog.ishrar.in/how-i-built-a-nuget-package</guid><category><![CDATA[Nuget]]></category><category><![CDATA[dotnet]]></category><category><![CDATA[GitHub]]></category><category><![CDATA[Open Source]]></category><category><![CDATA[package manager]]></category><dc:creator><![CDATA[Ishrar G]]></dc:creator><pubDate>Fri, 12 Jan 2024 10:29:19 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1705063168888/21ae5204-3386-4768-96df-4f52141a12fa.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>Open-source software has always been a cornerstone of the programming world, providing a platform for innovation and collaboration. Despite being a firm believer in its power, I never saw myself as someone who would contribute to this vast ecosystem. However, life often takes unexpected turns, and I found myself developing a NuGet package in C#.NET.</p>
<h2 id="heading-the-inspiration">The Inspiration</h2>
<p>The inspiration for this project came from a simple realization - I had a collection of functions that I frequently used across my projects. These functions were versatile, efficient, and most importantly, reusable. It dawned on me that these functions could be beneficial to other developers as well. So, I decided to package these functions into a library and make it open-source.</p>
<h2 id="heading-the-package">The Package</h2>
<p><a target="_blank" href="https://www.nuget.org/packages/SharpStackConvert/">SharpStackConvert</a> is a C# library that provides a collection of extended methods for type conversion and data manipulation. Here are some of its key features:</p>
<ul>
<li><p><strong>Type Conversion</strong>: The package includes extended methods for converting types, such as ToString, ToInt32, ToInt64. These methods make it easy to convert data types in C#, saving developers time and reducing potential errors.</p>
</li>
<li><p><strong>String to Base64 Conversion</strong>: SharpStackConvert allows you to convert strings to base64 and vice versa. This feature is particularly useful when you need to encode or decode data in base64 format.</p>
</li>
<li><p><strong>Hashing Methods</strong>: The package provides various hashing methods. Hashing is a common technique used in programming for a variety of purposes, such as data retrieval and password storage.</p>
</li>
<li><p><strong>List and Array Conversion</strong>: SharpStackConvert includes utilities for handling lists and arrays. It can convert these data structures to CSV and vice versa, making it easy to work with data in different formats.</p>
</li>
<li><p><strong>CSV to Table Conversion</strong>: One of the standout features of SharpStackConvert is its ability to convert CSV data to tables and vice versa. This feature is incredibly useful when working with large datasets, as it allows for easy data manipulation and analysis.</p>
</li>
</ul>
<p>In summary, SharpStackConvert is a versatile tool that aids C# developers in their day-to-day programming tasks. Its wide range of features makes it a valuable addition to any developer's toolkit.</p>
<h2 id="heading-the-journey">The Journey</h2>
<p>The journey of creating this NuGet package was an enlightening one. Here are the key steps I took:</p>
<ul>
<li><p><strong>Collection of Functions</strong>: I started by gathering all the functions that I had written for my various projects. These were functions that I found myself using repeatedly and realized they could be beneficial to other developers as well.</p>
</li>
<li><p><strong>Refinement with GitHub Copilot</strong>: Once I had all my functions, I used <a target="_blank" href="https://github.com/features/copilot">GitHub Copilot</a> to refine them. This AI-powered tool helped me optimize my code and make it more efficient.</p>
</li>
<li><p><strong>Naming the Package</strong>: After refining the functions, I gave the package a fitting name - SharpStackConvert. The name reflects its purpose and functionality.</p>
</li>
<li><p><strong>Creating a GitHub Repository</strong>: The next step was to create a <a target="_blank" href="https://github.com/ishrarg/SharpStackConvert/">GitHub repository for SharpStackConvert</a>. This would serve as the home for the package where developers could access it, provide feedback, and contribute to its development.</p>
</li>
<li><p><strong>Licensing with the MIT License</strong>: I decided to license SharpStackConvert with the <a target="_blank" href="https://github.com/ishrarg/SharpStackConvert/blob/main/LICENSE">MIT License</a>. This permissive license is simple and straightforward, allowing others to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the software.</p>
</li>
<li><p><strong>Writing the</strong> <a target="_blank" href="https://github.com/ishrarg/SharpStackConvert/blob/main/Readme.md"><strong>readme.md</strong></a> <strong>with ChatGPT and Bing AI</strong>: The final step was to write a comprehensive readme.md for the package. For this, I took the help of <a target="_blank" href="https://chat.openai.com/">ChatGPT</a> and <a target="_blank" href="https://chat.bing.com/">Bing AI</a>. These AI-powered tools helped me create a clear, concise, and informative readme that would guide developers on how to use SharpStackConvert.</p>
</li>
</ul>
<h2 id="heading-installation">Installation</h2>
<p>Installing SharpStackConvert is straightforward. You can use the NuGet package manager with the following command:</p>
<pre><code class="lang-csharp">PM&gt; NuGet\Install-Package SharpStackConvert -Version <span class="hljs-number">1.0</span><span class="hljs-number">.0</span><span class="hljs-number">.2</span>
</code></pre>
<p>Alternatively, you can use the dotnet CLI Command:</p>
<pre><code class="lang-csharp">dotnet <span class="hljs-keyword">add</span> package SharpStackConvert --version <span class="hljs-number">1.0</span><span class="hljs-number">.0</span><span class="hljs-number">.2</span>
</code></pre>
<h2 id="heading-the-community">The Community</h2>
<p>The .NET community has been incredibly supportive. The feedback I received after the 3rd update was overwhelmingly positive, which has inspired me to continue working on this project and contribute more to the open-source community.</p>
<p>I invite all .NET developers to use <strong>SharpStackConvert</strong>, test it, and provide feedback. Feel free to create issues in the GitHub repo and contribute by creating pull requests. Your contributions will not only help improve <strong>SharpStackConvert</strong> but also benefit the entire .NET community.</p>
<h2 id="heading-check-it-out-here">Check it out here</h2>
<p>Here are some important links related to SharpStackConvert:</p>
<ul>
<li><p><strong>NuGet Package</strong>: <a target="_blank" href="https://www.nuget.org/packages/SharpStackConvert/">SharpStackConvert</a></p>
</li>
<li><p><strong>GitHub Repository</strong>: <a target="_blank" href="https://github.com/ishrarg/SharpStackConvert">SharpStackConvert Repo</a></p>
</li>
<li><p><strong>Issues Section</strong>: <a target="_blank" href="https://github.com/ishrarg/SharpStackConvert/issues">GitHub Issues</a></p>
</li>
</ul>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Building SharpStackConvert has been a rewarding journey. It has taught me the value of sharing knowledge and how a simple idea can turn into a tool that benefits many. I'm excited to continue this journey, contribute more to the open-source community, and hopefully make a difference in the lives of other developers.</p>
<p>This is not an end but just a beginning of building a great project with the help of the community. The power of open-source lies in collaboration, and I look forward to seeing how SharpStackConvert evolves with the contributions from the .NET community.</p>
<p>Let's build a great thing for the entire C# community that has given us a lot over the years. Thank you for your support, and happy coding!</p>
<center><a href="https://www.freepik.com/free-photo/workplace-with-smartphone-laptop-black-table-top-view-copyspace-background_7760405.htm#query=blog%20background&amp;position=5&amp;from_view=keyword&amp;track=ais&amp;uuid=0ad4f801-c274-456e-9ab6-559ccef99cbc">Cover Image by Racool_studio  on Freepik</a></center>]]></content:encoded></item><item><title><![CDATA[Harmonizing Frontend and Backend: A Deep Dive into Angular and .NET Collaboration]]></title><description><![CDATA[Angular and .NET are two powerhouse technologies that are widely used in web application development. Each of these technologies brings a set of unique…]]></description><link>https://blog.ishrar.in/harmonizing-frontend-and-backend-a-deep-dive-into-angular-and-net-collaboration</link><guid isPermaLink="true">https://blog.ishrar.in/harmonizing-frontend-and-backend-a-deep-dive-into-angular-and-net-collaboration</guid><category><![CDATA[Angular]]></category><category><![CDATA[dotnet]]></category><category><![CDATA[Node.js]]></category><category><![CDATA[frontend]]></category><category><![CDATA[backend]]></category><dc:creator><![CDATA[Ishrar G]]></dc:creator><pubDate>Wed, 14 Jun 2023 06:42:42 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1686725681059/2846a2f6-c154-4f26-884b-01b91d326702.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Angular and .NET are two powerhouse technologies that are widely used in web application development. Each of these technologies brings a set of unique features to the table that can significantly enhance the functionality, performance, and usability of applications. When used in tandem, they can create robust, high-performance web applications that are easy to maintain, scalable, and user-friendly.</p>
<h3 id="heading-why-are-angular-and-net-suitable-together"><strong>Why are Angular and .NET Suitable Together?</strong></h3>
<p>The main reason why Angular and .NET are suitable together is that they are designed to handle different aspects of a web application.</p>
<p>Angular, a JavaScript framework developed and maintained by Google, is excellent for building dynamic and interactive client-side applications. It's rich in features, offering things like two-way data binding, modular architecture, and the ability to create single-page applications (SPAs), where all necessary code (HTML, CSS, and JavaScript) is retrieved with a single page load, or the appropriate resources are dynamically loaded and added to the page as necessary in response to user actions.</p>
<p>On the other hand, .NET is a server-side technology that's perfect for building robust backend services. Developed by Microsoft, .NET provides a stable, secure, and scalable environment for server-side programming. With .NET, you can create a wide range of applications, including web applications, desktop applications, and mobile applications.</p>
<p>In other words, Angular handles the presentation layer of the application (what the user interacts with), and .NET takes care of the logic and data management on the server-side.</p>
<h3 id="heading-when-to-choose-angular-and-net"><strong>When to Choose Angular and .NET?</strong></h3>
<p>Selecting Angular and .NET as your technology stack depends on the type of application you want to develop and the specific requirements of your project. Here are a few scenarios when Angular and .NET might be the perfect choice:</p>
<ul>
<li><p>If you are developing a web application with a complex user interface, you should choose Angular for the frontend due to its excellent features like data-binding, directives, and SPA capability.</p>
</li>
<li><p>If your application needs to handle a large amount of data securely and efficiently, you should use .NET for the backend. It provides a robust environment for data handling, processing, and storage.</p>
</li>
<li><p>If your team has proficiency in TypeScript, JavaScript, C#, and related technologies.</p>
</li>
<li><p>If your project requires a scalable, maintainable, and high-performing application.</p>
</li>
</ul>
<h3 id="heading-performance-perspective"><strong>Performance Perspective</strong></h3>
<p>From a performance perspective, using Angular with .NET is a winning combination. Angular's efficiency in handling dynamic and complex frontend tasks, coupled with .NET's robust backend capabilities, makes for a high-performance web application.</p>
<p>Angular uses change detection to ensure updates are propagated efficiently across the application, which helps to keep the user interface responsive. Furthermore, Angular's modular architecture and lazy loading capabilities help to keep initial load times low and improve overall performance.</p>
<p>On the backend side, .NET is highly optimized for performance. It uses the Just-In-Time (JIT) compilation for execution, which provides significant speed advantages. Also, the .NET runtime includes features like garbage collection and automatic memory management, which helps to keep your application running smoothly.</p>
<h3 id="heading-uiux-selection"><strong>UI/UX Selection</strong></h3>
<p>One of the significant advantages of using Angular for the frontend is the flexibility it provides in UI/UX design. Angular comes with a range of pre-built material design components, which not only accelerates the development process but also ensures consistency in design. Also, Angular's two-way data binding helps to create a more dynamic and interactive user experience.</p>
<p>Furthermore, because Angular is JavaScript-based, it allows for seamless integration with a wide range of JavaScript libraries and CSS frameworks, providing even more options for customizing your application's look and feel.</p>
<h3 id="heading-embracing-the-full-power-of-the-net-stack"><strong>Embracing the Full Power of the .NET Stack</strong></h3>
<p>When using Angular in conjunction with .NET, it's worth noting that the .NET framework is not limited to just building the backend services. The .NET stack offers a comprehensive suite of tools and technologies, from frontend to backend, that can help to elevate the quality and functionality of your application.</p>
<p>For instance, Blazor, a part of the .NET stack, is a feature-rich framework for building interactive client-side web UI using C# instead of JavaScript. With Blazor, you can create components using C# and Razor syntax, which can then be reused and shared across different parts of your application. This can bring about a significant improvement in code maintainability and productivity, especially for teams that are more proficient in C# than JavaScript.</p>
<p>Similarly, SignalR, another offering from .NET, provides real-time web functionality to applications. It allows bi-directional communication between server and client, which means the server can push updates to connected clients as they happen. This can be particularly useful in applications that require real-time data updates, such as chat apps, live auctions, collaborative apps, and more.</p>
<p>Thus, when considering Angular with .NET, it’s worth exploring the entire .NET stack to maximize the benefits of the powerful ecosystem that .NET provides. These tools and frameworks can significantly improve the capabilities of your application, offering a rich, interactive user experience and efficient, robust server-side processing.</p>
<p>Very soon I am going to publish a new article <strong><mark>Developing Angular .NET Application from Scratch</mark></strong></p>
<p>To summarize, Angular and .NET can create a potent combination for web development, providing the tools necessary to build high-performing, scalable, and user-friendly applications. The choice to use these technologies should be guided by the specific requirements of the project and the expertise of the development team.</p>
]]></content:encoded></item><item><title><![CDATA[Alternative to MS Interop to Export DataTable to Excel]]></title><description><![CDATA[Generate Excel file without using Excel library in C#]]></description><link>https://blog.ishrar.in/alternative-to-ms-interop-to-export-datatable-to-excel</link><guid isPermaLink="true">https://blog.ishrar.in/alternative-to-ms-interop-to-export-datatable-to-excel</guid><category><![CDATA[C#]]></category><category><![CDATA[excel]]></category><category><![CDATA[Microsoft]]></category><category><![CDATA[interop]]></category><category><![CDATA[closedxml]]></category><dc:creator><![CDATA[Ishrar G]]></dc:creator><pubDate>Tue, 05 Jul 2022 05:32:52 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1656754658912/unJ-0sY5F.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<blockquote>
<p>Ah no, I just built a whole code to export the data into Excel but the client does not have MS Office on their computer.</p>
</blockquote>
<p>Without wasting your time let me share with you why I am writing this article for you. There are scenarios when you will use this block of code given below.</p>
<ol>
<li><p>You wrote a block of code in C# WinForms or WPF to Export the data into Excel, but the client does not have MS Office installed on their computer.</p>
</li>
<li><p>You wrote the same using MS Interop but the client machine has a different MS OFfice version</p>
</li>
<li><p>Client Computer does not have InterOP installed</p>
</li>
<li><p>You want to use OpenSource Library to export to Excel</p>
</li>
</ol>
<p>I had almost all the challenges in different cases during my 15 years of experience with C#</p>
<p>Mostly I use <a target="_blank" href="https://github.com/ClosedXML/ClosedXML">ClosedXML</a> library which is OpenSource LIbrary. I have always had the best experience playing around with large excel files for better performance and easy implementation</p>
<h3 id="heading-closedxml-in-nuget">ClosedXML in Nuget</h3>
<p>Just easy to implement using nuget package</p>
<blockquote>
<p>PM&gt; Install-Package ClosedXML</p>
</blockquote>
<p>Here is a simple block of code to get it done easily.</p>
<pre><code class="lang-plaintext">using (var workbook = new XLWorkbook())
{
    var worksheet = workbook.Worksheets.Add("Sample Sheet");
    worksheet.Cell("A1").Value = "Hello World!";
    worksheet.Cell("A2").FormulaA1 = "=MID(A1, 7, 5)";
    workbook.SaveAs("HelloWorld.xlsx");
}
</code></pre>
<h3 id="heading-convert-datatable-to-excel-sheet-using-closedxml">Convert DataTable to Excel Sheet using ClosedXML</h3>
<p>I wanted to give you a just a ready method that will help you create an Excel File from the DataTable without Looping through the rows.</p>
<pre><code class="lang-plaintext">   public static void ConverTableToExcel(DataTable tblObject, string SheetName, string FilePath, bool OpenAfterSave)
        {
            try
            {

                string PathToSave = FilePath;
                if (PathToSave.Trim().Length == 0)
                {
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.Filter = "Excel Worksheets|*.xlsx";
                    if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        PathToSave = sfd.FileName;
                    }
                    else
                    {
                        return;
                    }
                }
                if (PathToSave.Length &gt; 0)
                {
                    XLWorkbook workBook = new XLWorkbook();
                    if (File.Exists(FilePath))
                    {
                        workBook = new XLWorkbook(FilePath);
                    }
                    IXLWorksheet ws = workBook.Worksheets.Add(tblObject, SheetName.Length &gt; 0 ? SheetName : "Sheet1");
                    ws.Unprotect();
                    Application.DoEvents();
                    workBook.SaveAs(PathToSave);

                    if (OpenAfterSave)
                    {

                        var p = new Process();
                        p.StartInfo = new ProcessStartInfo(PathToSave)
                        {
                            UseShellExecute = true
                        };
                        p.Start();

                    }
                    else
                    {

                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

            }

        }
</code></pre>
<h3 id="heading-how-to-export-a-datatable-into-excel-in-one-line">How to Export a DataTable into Excel in One Line?</h3>
<pre><code class="lang-plaintext"> ConverTableToExcel(tblConvertedForMatirixify, "Products", TempFilePath, false);
</code></pre>
<p>Bingo that's simple, easy, and a time saver. That's why I have kept in my code library which is used in all my Data Analysis tools development.</p>
<p>Soon I will share a similar thing to Export DataTable to CSV</p>
<p>Thanks.</p>
]]></content:encoded></item><item><title><![CDATA[Desktop based ERP Software]]></title><description><![CDATA[Building a huge software since 2013 for MSME Businessman to smoothly handle their business]]></description><link>https://blog.ishrar.in/desktop-based-erp-software</link><guid isPermaLink="true">https://blog.ishrar.in/desktop-based-erp-software</guid><category><![CDATA[dotnet]]></category><category><![CDATA[dotnetcore]]></category><category><![CDATA[SQL Server]]></category><category><![CDATA[Azure]]></category><category><![CDATA[CosmosDB]]></category><dc:creator><![CDATA[Ishrar G]]></dc:creator><pubDate>Tue, 05 Jul 2022 05:20:10 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-fraxinus-books-erp"><strong>Fraxinus Books ERP </strong></h2>
<p> An easy-to-use Desktop Application software that is helpful for Indian MSME Businesses to Manage their Inventory, Accounts, Production, GST, and business analysis without jumping into deep.</p>
<h2 id="heading-major-functionalities"><strong>Major Functionalities </strong></h2>
<ul>
<li>Sales - Orders, Delivery Challan, Invoice, Quotation, Proforma Invoice, Goods Return</li>
<li>Purchase - Orders, Delivery Challan, Invoice, Quotation, Proforma Invoice, Goods Return</li>
<li>Accounts - Receipt, Payments, Banks, Credit Note, Debit Note, Final Reports</li>
<li>Taxation - GST(GSTR1, GSTR2, GSTR3B, GSTR2A Reconciliation), Income Tax, TDS, TCS, EWay Bill, EInvoice</li>
</ul>
<p><strong>Development Started on</strong>: 01 August 2013
<strong>Last worked</strong>: Still Running
We are cooking this product since 2013 and still adding new tastes every day</p>
<p><strong>Technologies used</strong>
Primary Technologies: C#.Net WinForms in DotNet Framework 4.5, 
Database: SQL Server LocalDB or SQL Server Express or Azure SQL Server (Elastic)
Reporting: RDLC, Crystal Reports, HTML Reports</p>
<h2 id="heading-supportive-technical-features-and-technologies-used"><strong>Supportive Technical Features and Technologies used</strong></h2>
<h3 id="heading-licensing-system"><strong>Licensing System</strong>:</h3>
<p>Online Licensing is required to start working on the full software after a trial of 15 days. 
This system checks licensing details from WebAPIs, WCF, and Web Services (ASMX) to check license details from databases.</p>
<p>There are many internal services provided to users like </p>
<ul>
<li>GST Search - To fetch customer details by providing GST Number</li>
<li>EWay bills - To Upload EWay Bill from software without opening portal</li>
<li>E-Invoice - To Submit EInvoice to GST Department from software without opening portal</li>
<li>SMS notification - Send notification to Customer after invoicing</li>
<li>WhatsApp Notification - Send whatsapp notification to customer after invoicing or outstanding reminders</li>
</ul>
<p>All these services are built using a combination of WCF, Azure Functions and .Net Core WebAPI</p>
<p><strong>Other supportive tools </strong>to help product give more advantages like </p>
<h3 id="heading-backup-tool"><strong>Backup Tool  </strong></h3>
<p> Helps to upload backup on Google Drive using Google OAuth or upload the backup on Company Server (Azure blob storage).</p>
<h3 id="heading-web-portal"><strong>Web Portal</strong></h3>
<p>To allow users to submit customer orders, customer payments, quotations etc. Users can see the customer's reports from the portal - Developed using these technologies: ASP.Net MVC, Bootstrap, Azure SQL Server, Azure Storage, Azure Web Apps, Azure Web Jobs</p>
<h3 id="heading-order-booking-portal-for-customer"><strong>Order Booking Portal for Customer</strong></h3>
<p>Portal for customers to Book Orders, check statements, check payments and do new payments.
Technologies used: ASP.Net Core 3.1, Razor Pages, Bootstrap, Ajax, JQuery, Azure SQL Server</p>
<h3 id="heading-other-technologies">Other technologies</h3>
<p>Technologies I used that are not listed above to Build, Run, Deploy, Manage, Improve, observe and support the above product.</p>
<ul>
<li>Visual Studio 2019</li>
<li>Git</li>
<li>Tortoise Git</li>
<li>SourceTree</li>
<li>Bitbucket,</li>
<li>CodeCommit</li>
<li>Azure DevOps</li>
<li>Jira,</li>
<li>Trello</li>
<li>Asana</li>
</ul>
<ul>
<li>Azure SQL Elastic Pool :</li>
<li>Database Firewall</li>
<li>Entity Framework :</li>
<li>CosmosDB</li>
<li><p>Azure Blob Storage</p>
</li>
<li><p>Azure Web Apps</p>
</li>
<li>Razor Pages</li>
<li>Azure Web Jobs</li>
<li>Azure Functions</li>
<li>Ajax, JQuery, Bootstrap</li>
<li><p>CDN</p>
</li>
<li><p>SMTP</p>
</li>
<li>FTP</li>
<li>TCP Port</li>
<li>Google OAuth</li>
<li>Google Firebase URL Shortner</li>
<li><p>NodeJS</p>
</li>
<li><p>Microsoft.Interop.Excel</p>
</li>
<li>ClosedXML</li>
<li>iTextShartp</li>
<li>Document Signing - Electronic Signature</li>
<li>CryptoLib</li>
</ul>
<ul>
<li>Obfusecator</li>
<li>SignTool</li>
<li>CodeSign</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Create Dynamic Mathematical Formula in C#]]></title><description><![CDATA[Ready to use solution to create any dynamic mathematical formula in C Sharp.]]></description><link>https://blog.ishrar.in/create-dynamic-mathematical-formula-in-csharp</link><guid isPermaLink="true">https://blog.ishrar.in/create-dynamic-mathematical-formula-in-csharp</guid><category><![CDATA[C#]]></category><category><![CDATA[shopify]]></category><category><![CDATA[excel]]></category><category><![CDATA[expression]]></category><category><![CDATA[SFTP]]></category><dc:creator><![CDATA[Ishrar G]]></dc:creator><pubDate>Sat, 02 Jul 2022 08:11:03 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1656749170883/onV2g4YVk.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-why-do-we-need-dynamic-math-formula">Why do we need Dynamic Math Formula?</h3>
<p> I was working on a project yesterday, where I was uploading items on the Shopify website in bulk by looping on Excel. </p>
<p>The user's requirement was to create items by changing the sales price with the formula and the user must be able to change the formula for the sales price based on cost.</p>
<p>I was literally worried about giving this solution in a short time because I planned to build this thing. </p>
<p>Currently, the client has a formula for the sales <code>price = ItemCost * 2 +15.</code> They want to change the formula based on different scenarios. </p>
<p>I built it using the solution explained on StackOverflow <a target="_blank" href="https://stackoverflow.com/questions/34138314/creating-dynamic-formula">here</a></p>
<p>This answer on Stackoverflow explained the solution perfectly for my requirement. </p>
<blockquote>
<p>Wise people always Google it before inventing.</p>
</blockquote>
<h3 id="heading-build-a-class-to-calculate-dynamic-formula-in-c">Build a Class to Calculate Dynamic Formula in C</h3>
<p>Have a look at the class and the method which handles the formula for Multiplication, division, addition and subtraction.</p>
<pre><code><span class="hljs-keyword">public</span> class DynamicFormula
{
    <span class="hljs-comment">/// &lt;summary&gt;</span>
    <span class="hljs-comment">/// This simply stores a variable name and its value so when this key is found in a expression it gets the value accordingly.</span>
    <span class="hljs-comment">/// &lt;/summary&gt;</span>
    <span class="hljs-keyword">public</span> Dictionary<span class="hljs-operator">&lt;</span><span class="hljs-keyword">string</span>, double<span class="hljs-operator">&gt;</span> Variables { get; <span class="hljs-keyword">private</span> set; }

    <span class="hljs-comment">/// &lt;summary&gt;</span>
    <span class="hljs-comment">/// The expression itself, each value and operation must be separated with SPACES. The expression does not support PARENTHESES at this point.</span>
    <span class="hljs-comment">/// &lt;/summary&gt;</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">string</span> Expression { get; set; }

    <span class="hljs-keyword">public</span> DynamicFormula()
    {
        <span class="hljs-built_in">this</span>.Variables <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> Dictionary<span class="hljs-operator">&lt;</span><span class="hljs-keyword">string</span>, double<span class="hljs-operator">&gt;</span>();
    }

    <span class="hljs-keyword">public</span> double CalculateResult()
    {
        <span class="hljs-keyword">if</span> (<span class="hljs-keyword">string</span>.IsNullOrWhiteSpace(<span class="hljs-built_in">this</span>.Expression))
            <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> Exception(<span class="hljs-string">"An expression must be defined in the Expression property."</span>);

        double? result <span class="hljs-operator">=</span> null;
        <span class="hljs-keyword">string</span> operation <span class="hljs-operator">=</span> <span class="hljs-keyword">string</span>.Empty;

        <span class="hljs-comment">//This will be necessary for priorities operations such as parentheses, etc... It is not being used at this point.</span>
        List<span class="hljs-operator">&lt;</span>double<span class="hljs-operator">&gt;</span> aux <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> List<span class="hljs-operator">&lt;</span>double<span class="hljs-operator">&gt;</span>();  

        foreach (<span class="hljs-keyword">var</span> lexema in Expression.Split(<span class="hljs-keyword">new</span> <span class="hljs-keyword">string</span>[] { <span class="hljs-string">" "</span> }, StringSplitOptions.RemoveEmptyEntries))
        {
            <span class="hljs-comment">//If it is an operator</span>
            <span class="hljs-keyword">if</span> (lexema <span class="hljs-operator">=</span><span class="hljs-operator">=</span> <span class="hljs-string">"*"</span> <span class="hljs-operator">|</span><span class="hljs-operator">|</span> lexema <span class="hljs-operator">=</span><span class="hljs-operator">=</span> <span class="hljs-string">"/"</span> <span class="hljs-operator">|</span><span class="hljs-operator">|</span> lexema <span class="hljs-operator">=</span><span class="hljs-operator">=</span> <span class="hljs-string">"+"</span> <span class="hljs-operator">|</span><span class="hljs-operator">|</span> lexema <span class="hljs-operator">=</span><span class="hljs-operator">=</span> <span class="hljs-string">"-"</span>)
            {
                operation <span class="hljs-operator">=</span> lexema;
            }
            <span class="hljs-keyword">else</span> <span class="hljs-comment">//It is a number or a variable</span>
            {
                double value <span class="hljs-operator">=</span> double.MinValue;
                <span class="hljs-keyword">if</span> (Variables.ContainsKey(lexema.ToLower())) <span class="hljs-comment">//If it is a variable, let's get the variable value</span>
                    value <span class="hljs-operator">=</span> Variables[lexema.ToLower()];
                <span class="hljs-keyword">else</span> <span class="hljs-comment">//It is just a number, let's just parse</span>
                    value <span class="hljs-operator">=</span> double.Parse(lexema);

                <span class="hljs-keyword">if</span> (<span class="hljs-operator">!</span>result.HasValue) <span class="hljs-comment">//No value has been assigned yet</span>
                {
                    result <span class="hljs-operator">=</span> value;
                }
                <span class="hljs-keyword">else</span>
                {
                    switch (operation) <span class="hljs-comment">//Let's check the operation we should perform</span>
                    {
                        case <span class="hljs-string">"*"</span>:
                            result <span class="hljs-operator">=</span> result.Value <span class="hljs-operator">*</span> value;
                            <span class="hljs-keyword">break</span>;
                        case <span class="hljs-string">"/"</span>:
                            result <span class="hljs-operator">=</span> result.Value <span class="hljs-operator">/</span> value;
                            <span class="hljs-keyword">break</span>;
                        case <span class="hljs-string">"+"</span>:
                            result <span class="hljs-operator">=</span> result.Value <span class="hljs-operator">+</span> value;
                            <span class="hljs-keyword">break</span>;
                        case <span class="hljs-string">"-"</span>:
                            result <span class="hljs-operator">=</span> result.Value <span class="hljs-operator">-</span> value;
                            <span class="hljs-keyword">break</span>;
                        default:
                            <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> Exception(<span class="hljs-string">"The expression is not properly formatted."</span>);
                    }
                }
            }
        }

        <span class="hljs-keyword">if</span> (result.HasValue)
            <span class="hljs-keyword">return</span> result.Value;
        <span class="hljs-keyword">else</span>
            <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> Exception(<span class="hljs-string">"The operation could not be completed, a result was not obtained."</span>);
    }
    <span class="hljs-comment">/// &lt;summary&gt;</span>
    <span class="hljs-comment">/// Add variables to the dynamic math formula. The variable should be properly declared.</span>
    <span class="hljs-comment">/// &lt;/summary&gt;</span>
    <span class="hljs-comment">/// &lt;param name="variableDeclaration"&gt;Should be declared as "VariableName=VALUE" without spaces&lt;/param&gt;</span>
    <span class="hljs-keyword">public</span> void AddVariable(<span class="hljs-keyword">string</span> variableDeclaration)
    {            
        <span class="hljs-keyword">if</span> (<span class="hljs-operator">!</span><span class="hljs-keyword">string</span>.IsNullOrWhiteSpace(variableDeclaration))
        {
            <span class="hljs-keyword">var</span> variable <span class="hljs-operator">=</span> variableDeclaration.ToLower().Split(<span class="hljs-string">'='</span>);    <span class="hljs-comment">//Let's make sure the variable's name is LOWER case and then get its name/value</span>
            <span class="hljs-keyword">string</span> variableName <span class="hljs-operator">=</span> variable[<span class="hljs-number">0</span>];
            double variableValue <span class="hljs-operator">=</span> <span class="hljs-number">0</span>;

            <span class="hljs-keyword">if</span> (double.TryParse(variable[<span class="hljs-number">1</span>], out variableValue))
                <span class="hljs-built_in">this</span>.Variables.Add(variableName, variableValue);
            <span class="hljs-keyword">else</span>
                <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> ArgumentException(<span class="hljs-string">"Variable value is not a number"</span>);
        }
        <span class="hljs-keyword">else</span>
        {
            <span class="hljs-comment">//Could throw an exception... or just ignore as it not important...</span>
        }
    }
}
</code></pre><p>The Above class Accepts Mathematical Expression and Variable Values to be used in Expression. 
When we execute <code>CalculateResult()</code> method it gives calculated result.</p>
<p>Here is what I did in my project, I just created a simple object of DynamicFormula, and passed the Expression and Variables. 
Just by calling <code>CalculateResult()</code> method my result is there. 
Have a look at the code in my project</p>
<h3 id="heading-calculating-dynamic-formula-using-expression-and-variables-in-c">Calculating Dynamic Formula using Expression and Variables in C</h3>
<pre><code><span class="hljs-keyword">string</span> priceFormula <span class="hljs-operator">=</span> CommonFunctions.EnvironmentSettings.PriceFormula;
<span class="hljs-keyword">try</span>
{
    <span class="hljs-comment">//This was my static formula before</span>
    <span class="hljs-comment">//decimal price = decimal.Parse(i.Variant_Cost);</span>
    <span class="hljs-comment">//price = (price * 2) + 10;</span>
    <span class="hljs-comment">//i.Variant_Price = price.ToString();</span>
    <span class="hljs-comment">//------------------------------------------</span>
    DynamicFormula f <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> DynamicFormula();
    f.Expression <span class="hljs-operator">=</span> priceFormula;
    f.AddVariable(<span class="hljs-string">"cost="</span> <span class="hljs-operator">+</span> i.Variant_Cost);
    double result <span class="hljs-operator">=</span> f.CalculateResult();
    i.Variant_Price <span class="hljs-operator">=</span> result.ToString();
}
<span class="hljs-keyword">catch</span> (Exception ex)
{
    i.Variant_Price <span class="hljs-operator">=</span> <span class="hljs-string">""</span>;
}
</code></pre><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1656747160581/RHBoX4heK.png" alt="image.png" /></p>
<p>If you have such a similar requirement you can use this solution given by <a target="_blank" href="https://stackoverflow.com/users/2169916/luishg">luishg</a>.</p>
]]></content:encoded></item></channel></rss>