My Short Note

Use Session from Class Library (or Class Library Project)

Add First we need to add System.Web as a reference on our project.


How to write connection string in web.config file

At first we need to add following namespace

using System.Collections.Generic;
using System.Web.Configuration;

Now use following code to write on web.config file

            Configuration config;
            ConnectionStringsSection connectString;
            config = WebConfigurationManager.OpenWebConfiguration("~");
            connectString = (ConnectionStringsSection)config.GetSection("connectionStrings");
            connectString.ConnectionStrings["DBCons"].ConnectionString = "My-New-ConnectString";

How to get SerVer.MapPath() from a Class file


Rounded corner Panel in C# Win Application

private void panel1_Paint(object sender, PaintEventArgs e)

      Graphics v=e.Graphics;
      DrawRoundRect(v,Pens.Blue, e.ClipRectangle.Left, e.ClipRectangle.Top, e.ClipRectangle.Width - 1, e.ClipRectangle.Height - 1,10);
       //Without rounded corners
      //e.Graphics.DrawRectangle(Pens.Blue, e.ClipRectangle.Left, e.ClipRectangle.Top, e.ClipRectangle.Width - 1, e.ClipRectangle.Height - 1);

Checking is Internet Connection exist using C#


Consider following function for checking internet connection. This function will return false if there is no internet connection.

private bool IsInternetConnectionExist()
                System.Net.IPHostEntry objIPHE = System.Net.Dns.GetHostEntry("");
                return true;
            catch (Exception)
                return false;

Access Tip : IsNull Equivalent
IsNUll equivalent in ms access

SELECT IIF(Value Is NULL, 0, Value) FROM Values


Accessing CSV File/ Accessing txt file using Odbc
Consider following code for reading from csv file

  string strConString = @"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq="+ Application.StartupPath.ToString() +"\;Extensions=csv,txt";
            var con = new OdbcConnection(strConString);
            var dataAdapter = new OdbcDataAdapter("Select * from [tst.csv]", con); // for txt [tst.txt]
            var dataTable = new DataTable();
            dataAdapter.Fill(dataTable );
            dataGridView1.DataSource = dataTable;

Getting Plain text from HTML

string htmlString = @"<p>I'm HTML!</p>
Regex.Replace(htmlString, @"<(.|n)*?>", "");