My Short Note

Use Asp.net Session from Class Library (or Class Library Project)

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

System.Web.HttpContext.Current.Session[“MyVariable”];
System.Web.HttpContext.Current.Session(“MyVariable”);

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";
            config.Save();

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

System.Web.HttpContext.Current.Server.MapPath("~/")

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);
      base.OnPaint(e);
    }

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()
        {
            try
            {
                System.Net.IPHostEntry objIPHE = System.Net.Dns.GetHostEntry("www.google.com");
                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);
            con.Open();
            var dataAdapter = new OdbcDataAdapter("Select * from [tst.csv]", con); // for txt [tst.txt]
            var dataTable = new DataTable();
            dataAdapter.Fill(dataTable );
            con.Close();
            dataAdapter.Dispose();
            dataGridView1.DataSource = dataTable;

Getting Plain text from HTML

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