Featured Articles

Decoration

All Stories

Wednesday, 3 November 2021

Read HTML File in C#

 In this article i will show you how you can read a html file content in string variable using c#.net. This trick to read html file using c#.net can be used in Asp.net core, MVC and asp.net application, Console application. 

This article will cover following topics:

  • Read HTML file from folder C#
  • How to read html file line by line in c#
  • How to read html file in asp.net using c#
  • How to convert html file to string in c#
  • Read html file in net core
  • How to read web page content in c#
  • Blazor read html file

Now first we will create a HTML file and add some content.

Read HTML File in C#

Now for this article first we will create a new application and add the below code into your application.

  public ActionResult Index()

        {

            string content = System.IO.File.ReadAllText(Server.MapPath("~/HtmlFile/TestHtmlFile.html"));

            return View();

        }

 In above code i have read the file on a path.

Read HTML File in C#

Now run the application and to check the output.

Read HTML File in C#

Now check the detail output.

Read HTML File in C#


11/03/2021 - By Pranav Singh 0

Friday, 29 October 2021

Extracting String Between Two Characters By Regex in C# (Asp.Net Core, MVC, Console)

This article will show you how you can extract string between two characters using regex in C#. This you can use in asp.net core, MVC and console application. This will help you to get string between character using regex c#. It will cover following topics.


  • Get string between two special characters regex
  • How to extract a string between two delimiters
  • Regex get string between two brackets
  • Regex find string between two characters
  • Replace string between two special characters
  • How to split string between two characters in c#
  • Extract string between two characters

 

Suppose you have a string  


You visited following country first #India#, Second country #Nepal#, Third Country #United Kingdom#.

 

Now we will write code to extract all the country names. For this create a new console application and add the below code.


static void Main(string[] args)

        {

            string userinput = "You visited following country first #India#, Second country #Nepal#, Third Country #United Kingdom#.";

            //For getting output in comman seprated string

            var outputstring = String.Join(";", Regex.Matches(userinput, @"\#(.+?)\#")

                                    .Cast<Match>()

                                    .Select(m => m.Groups[1].Value));

            //for getting data in list format

            var outputlist = String.Join(";", Regex.Matches(userinput, @"\#(.+?)\#")

                                    .Cast<Match>()

                                    .Select(m => m.Groups[1].Value)).Split(';');

        }

 

In above code we are having two part first part to get output as string


string userinput = "You visited following country first #India#, Second country #Nepal#, Third Country #United Kingdom#.";

            //For getting output in comman seprated string

            var outputstring = String.Join(";", Regex.Matches(userinput, @"\#(.+?)\#")

                                    .Cast<Match>()

                                    .Select(m => m.Groups[1].Value));

 

Output as List:

  //for getting data in list format

            var outputlist = String.Join(";", Regex.Matches(userinput, @"\#(.+?)\#")

                                    .Cast<Match>()

                                    .Select(m => m.Groups[1].Value)).Split(';');

 

Now run the application and check the output.

Output as String:

Extracting String Between Two Characters By Regex in C# (Asp.Net Core, MVC, Console)


Output as List:
 

 

Extracting String Between Two Characters By Regex in C# (Asp.Net Core, MVC, Console)

 

10/29/2021 - By Pranav Singh 0

Wednesday, 14 July 2021

Convert Decimal Number / Currency To Words In C#.net

In this article we will she how we can convert the number or decimal number or currency into words using C#.net.  In this article we will cover below topics:

  1. Convert decimal number to words in c#.net
  2. Convert Numbers To Words In C#
  3. Convert Numeric Value Into Words (Currency) In C#
  4. Convert number with decimals (in currency) to words
  5. C# Number (Decimal) to word converter in Dollar

So for this first we you need a c# library to convert the decimal into words using c#.net in console application.  You can download the library code from here. You just need to include this code into your application.

Download 

Now we will prepare a console application and add the below code.

 

using System;

using System.Collections.Generic;

using System.IO;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using Aspdotnetpools.DecimalToWordExtension;

namespace ConsoleApp1

{

       class Program

       {

        static void Main(string[] args)

        {

            decimal val =Convert.ToDecimal(1000000.456);

               Console.WriteLine(DecimalToWordExtension.ToWords(val));

            Console.ReadLine();

        }

       }

}

 

 

In above code I have added the included Aspdotnetpools.DecimalToWordExtension into the project and then converted the word. Here is the output.

Convert Decimal Number / Currency To Words In C#.net


7/14/2021 - By Pranav Singh 0

Thursday, 8 July 2021

How to View/Display File After Uploading in App_Data In Asp.net Using C#.Net

In this article I will show you how you can display file or document or PDF file present in App_Data folder in browser in after uploading in asp.net application using C#.Net and VB.Net.

You May Also Like:

 How to Extract Text From PDF File Using C#.Net

Code to Export GridView to PDF in Asp.Net Using C# and Vb.Net


Suppose you have PDF file in you’re App_Data folder. Now follow the step to show the PDF file in your asp.net application.

Step 1:

In this step we will add PDF file in our App_Data folder.

App_data folder in asp.net

Step 2:

In this step we will add a new asp.net page on which we will display the App_Data folder.

Step 3:

Follow the below mention code to convert the PDF file into Byte array string.

     public void     PDFDisplay()

        {

            string fileFolderPath = "~/App_Data/professional-cloud-architect.pdf ";

            String file = Convert.ToBase64String(File.ReadAllBytes(Server.MapPath(fileFolderPath)));

            byte[] bytes = Convert.FromBase64String(bytePDF);

            Response.Clear();

            Response.ContentType = "application/pdf";

            Response.Buffer = true;

               Response.Cache.SetCacheability(HttpCacheability.NoCache);

            Response.BinaryWrite(bytes);

            Response.End();

            Response.Close();

        }

 

Here in above code I have first stored the App_Data folder file path in a string variable and after that converted it into base64bit string.

Now through the Response.BinaryWrite function the PDF file file have been displayed on the screen. Now run the application and check the output.


How to Open PDF Files in Web Brower Using ASP.NET


You May Also Like:

 iTextSharp To Create PDF In C#

Export Html To PDF In Asp.Net C#

7/08/2021 - By Pranav Singh 0

Monday, 5 July 2021

How To Get Selected Values Of CheckBoxList With Foreach/LINQ in ASP.NET C#?

In this article I will show you how you can get the selected value of your checkboxlist in your asp.net application using c#.net. in this I will use LINQ and for look to get the selected checkboxlist value your can get.   

How To Get Selected Values Of CheckBoxList With Foreach/LINQ in ASP.NET C#?


So first we will take a checkboxlist control and bind some value. 


     <asp:CheckBoxList ID="cblItemType" runat="server" RepeatDirection="Horizontal">

                <asp:ListItem>Item1</asp:ListItem>

                <asp:ListItem>Item2</asp:ListItem>

                <asp:ListItem>Item3</asp:ListItem>

            </asp:CheckBoxList>

 

Now here are the code:

With LINQ to get selected item value:

     List<string> selectedItem = cblItemType.Items.Cast<ListItem>()

                                                    .Where(li => li.Selected)

                                                    .Select(li => li.Value)

                                                    .ToList();

 

With Foreach:

List<string> selectedItem = new List<string>();

                    foreach(ListItem item in cblItemType.Items)

                    {

                        if (item.Selected)

                        {

                               selectedItem.Add(item.Value);

                        }

                    }

 

Now run the article to check the output.

 

7/05/2021 - By Pranav Singh 0

Friday, 2 July 2021

How to Create/Build Registration From


This article will show you how you can create registration form in c#.net with SQL database. So in this article I have used Ms SQL server database. In this I will save the user login detail into sql table by using c#.net

7/02/2021 - By Pranav Singh 0

How To Build/Create a Login Form (CSS, jQuery For Asp.net, .Net Core and MVC Application)

In this article i will show you how you can create a responsive login form using css, HTML and jQuery.  For this article first we will create a web application and add a new page in it. Now we will design the login form.


So first we will add the below references into the page header. 


       <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" />

       <script src="https://code.jquery.com/jquery-1.12.4.js"></script>

    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

 

After adding this references we will design our login form. Please check the code.


        <div>

            <input type="button" value="Click to Open Login" class="ui-button ui-icon-alert" id="openloginform" />

        </div>

 

        <!-- This is your login form area-->

        <div id="dialog-form" title="LOGIN AREA">

            <p style="text-align: center;">

                <img src="Login-icon.png" width="150px" />

            </p>

            <p>

                <span  style="float: left; margin: 0 7px 0px 0;font-weight:bold;">Login Id</span>

                <input type="text" class="text" />

            </p>

            <p>

                <span style="float: left; margin: 0 7px 0px 0; font-size: 15px;font-weight:bold;">Password</span>

                <input type="password" class="text" />

            </p>

            <p>

                <input type="button" class="ui-button" value="Login" />

            </p>

        </div>

 

In above code i have added a button control. When user click on the button it will open the login form. Just below the button logon form html tag have been added.

Now we will add the jQuery code which make the login form open the an animated form inside the model popup window.


     $(function () {

            $("#dialog-form").dialog({

                autoOpen: false,

                show: {

                    effect: "blind",

                    duration: 1000

                }

            });

            $("#openloginform").on("click"function () {

                $("#dialog-form").dialog("open");

            });

        });

 

Now here is the complete code of the page. 


<!DOCTYPE html>

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

       <title>How to create a login form</title>

       <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" />

       <script src="https://code.jquery.com/jquery-1.12.4.js"></script>

       <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

       <style>

        input[type=text]input[type=password] {

            width100%;

            padding12px 20px;

            margin8px 0;

            displayinline-block;

            border1px solid #ccc;

            box-sizingborder-box;

        }

       </style>

       <script>

        $(function () {

            $("#dialog-form").dialog({

                autoOpen: false,

                show: {

                    effect: "blind",

                    duration: 1000

                }

            });

            $("#openloginform").on("click"function () {

                $("#dialog-form").dialog("open");

            });

        });

       </script>

 

</head>

<body>

           <div>

            <input type="button" value="Click to Open Login" class="ui-button ui-icon-alert" id="openloginform" />

        </div>

 

        <!-- This is your login form area-->

        <div id="dialog-form" title="LOGIN AREA">

            <p style="text-align: center;">

                <img src="Login-icon.png" width="150px" />

            </p>

            <p>

                <span  style="float: left; margin: 0 7px 0px 0;font-weight:bold;">Login Id</span>

                <input type="text" class="text" />

            </p>

            <p>

                <span style="float: left; margin: 0 7px 0px 0; font-size: 15px;font-weight:bold;">Password</span>

                <input type="password" class="text" />

            </p>

            <p>

                <input type="button" class="ui-button" value="Login" />

            </p>

        </div>

</body>

</html>

 

 

Now we have done open the page in browser to check the output.

Hot to create a login form

Download

7/02/2021 - By Pranav Singh 0

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top