Friday, September 27, 2013

Set Expiration Values for ASP.NET Page Caching

c#

Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetValidUntilExpires(true);
 
vb
 
Response.Cache.SetExpires(DateTime.Now.AddSeconds(60))
Response.Cache.SetCacheability(HttpCacheability.Public)
Response.Cache.SetValidUntilExpires(True) 

very useful htaccess tips & tricks

Apache web servers has a great way to manipulate information using .htaccess files. .htaccess (hypertext access) is the default name of a directory-level configuration file that allows for decentralized management of web server configuration. The .htaccess file is placed inside the web tree, and is able to override a subset of the server’s global configuration; the extent of this subset is defined by the web server administrator. The original purpose of .htaccess was to allow per-directory access control (e.g. requiring a password to access the content), hence the name. Nowadays .htaccess can override many other configuration settings, mostly related to content control, e.g. content type and character set, CGI handlers, etc.

Following are few very useful htaccess tricks.

 

 

1. Custom Directory Index Files

DirectoryIndex index.html index.php index.htm
You can change a default index file of directory by using above snippet in your htaccess file. If a user request /foo/, Apache will serve up /foo/index.html, or whatever file you specify.

2. Custom Error Pages

ErrorDocument 404 errors/404.html
You may want to redirect your users to an error page is any of the http errors like 404 occurs. You can use above snippet in htaccess file to map 404 error to error page errors/404.html. Also you may want to write a common page for all the http errors as follows:
ErrorDocument 404 /psych/cgi-bin/error/error?404

3. Control access at files & directory level

.htaccess is most often used to restrict or deny access to individual files and folders. A typical example would be an “includes” folder. Your site’s pages can call these included scripts all they like, but you don’t want users accessing these files directly, over the web. In that case you would drop an .htaccess file in the includes folder with content something like this.
# no one gets in here!
deny from all
which would deny ALL direct access to ANY files in that folder. You can be more specific with your conditions, for instance limiting access to a particular IP range, here’s a handy top-level rule for a local test server.
# no nasty crackers in here!
order deny,allow
deny from all
allow from 192.168.0.0/24
# this would do the same thing..
#allow from 192.168.0
Generally these sorts of requests would bounce off your firewall anyway, but on a live server they become useful for filtering out undesirable IP blocks, known risks, lots of things.
Sometimes, you will only want to ban one IP, perhaps some persistent robot that doesn’t play by the rules.
# someone else giving the ruskies a bad name..
order allow,deny
deny from 83.222.23.219
allow from all

4. Modifying the Environment Variable

Environment variables contain information used by server-side includes and CGI. Set / Unset environment variables using SetEnv and UnSetEnv.
SetEnv SITE_WEBMASTER "Jack Sprat"
SetEnv SITE_WEBMASTER_URI mailto:Jack.Sprat@characterology.com
UnSetEnv REMOTE_ADDR

5. 301 Redirect using htaccess

If you want to redirect from an old document to new:
Redirect 301 /old/file.html http://yourdomain.com/new/file.html
Use following for redirecting Entire Directory.
RedirectMatch 301 /blog(.*) http://yourdomain.com/$1

6. Implementing a Caching Scheme with .htaccess

Cache the static files and improve your website’s performance.
# year
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$">
Header set Cache-Control "public"
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
Header unset Last-Modified
</FilesMatch>
#2 hours
<FilesMatch "\.(html|htm|xml|txt|xsl)$">
Header set Cache-Control "max-age=7200, must-revalidate"
</FilesMatch>
<FilesMatch "\.(js|css)$">
SetOutputFilter DEFLATE
Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
</FilesMatch>

7. Compress output using GZIP

Add following snippet into your htaccess file and compress all the css, js, html files with GZip compression.
<IfModule mod_gzip.c>
    mod_gzip_on       Yes
    mod_gzip_dechunk  Yes
    mod_gzip_item_include file      \.(html?|txt|css|js|php|pl)$
    mod_gzip_item_include handler   ^cgi-script$
    mod_gzip_item_include mime      ^text/.*
    mod_gzip_item_include mime      ^application/x-javascript.*
    mod_gzip_item_exclude mime      ^image/.*
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>
Above code works only if mod_gzip module is enabled in your webserver. You may want to add following snippet if your webserver provides mod_deflate support.
<Location>
    SetOutputFilter DEFLATE
      SetEnvIfNoCase Request_URI  \
        \.(?:gif|jpe?g|png)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI  \
        \.(?:exe|t?gz|zip|gz2|sit|rar)$ no-gzip dont-vary
</Location>
If your webserver does not support mod_deflate then you may want to use following snippet.
<FilesMatch "\.(txt|html|htm|php)">
    php_value output_handler ob_gzhandler
</FilesMatch>

8. Redirect browser to https (ssl)

Add following snippet to your htaccess and redirect entire website to https.
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

9. Rewrite URLs using htacccess

Rewriting product.php?id=12 to product-12.html
RewriteEngine on
RewriteRule ^product-([0-9]+)\.html$ product.php?id=$1
Rewriting product.php?id=12 to product/ipod-nano/12.html
RewriteEngine on
RewriteRule ^product/([a-zA-Z0-9_-]+)/([0-9]+)\.html$ product.php?id=$2
Redirecting non www URL to www URL
RewriteEngine On
RewriteCond %{HTTP_HOST} ^viralpatel\.net$
RewriteRule (.*) http://www.viralpatel.net/$1 [R=301,L]
Rewriting yoursite.com/user.php?username=xyz to yoursite.com/xyz
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1
Redirecting the domain to a new subfolder of inside public_html
RewriteEngine On
RewriteCond %{HTTP_HOST} ^test\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.test\.com$
RewriteCond %{REQUEST_URI} !^/new/
RewriteRule (.*) /new/$1

10. Prevent Directory Listing

Add any of the following snippet to avoid directory listing.
Options -Indexes
or
IndexIgnore *

11. Adding new MIME types

The type of file depends on the filename extension. Unrecognized file extensions are treated as text data, and corrupted on download.
AddType application/x-endnote-connection enz
AddType application/x-endnote-filter enf
AddType application/x-spss-savefile sav

12. Deny access to static file data

Denies any request for static files (images, css, etc) if referrer is not local site or empty.
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteCond %{HTTP_REFERER} !^http://www.askapache.com.*$ [NC]
RewriteRule \.(ico|pdf|flv|jpg|jpeg|mp3|mpg|mp4|mov|wav|wmv|png|gif|swf|css|js)$ - [F,NS,L]

13. Specify Upload file limit for PHP in htaccess

php_value upload_max_filesize 20M
php_value post_max_size 20M
php_value max_execution_time 200
php_value max_input_time 200
In the above .htaccess file, uploading capability is increased by the four parameter first one is maximum file size for uploading, second one is maximum size of the post data , third one is maximum time in seconds a script is allowed to run before it is terminated by the parser and last one is maximum time in seconds a script is allowed to parse input data such as like file uploads, POST and GET data.

14. Disallow Script Execution

Options -ExecCGI
AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi

15. Change Charset and Language headers

AddDefaultCharset UTF-8
DefaultLanguage en-US

16. Set Timezone of the Server (GMT)

SetEnv TZ America/Indianapolis

17. Force “File Save As” Prompt

AddType application/octet-stream .avi .mpg .mov .pdf .xls .mp4

18. Protecting a single file

Normally .htaccess applies to the entire directory. With the directive you can restrict it to specific files:
<Files quiz.html>
order deny,allow
deny from all
AuthType Basic
AuthName "Characterology Student Authcate"
AuthLDAP on
AuthLDAPServer ldap://directory.characterology.com/
AuthLDAPBase "ou=Student, o=Characterology University, c=au"
require valid-user
satisfy any
</Files>

19. Set Cookie using htaccess

Set Cookie with environment variable
Header set Set-Cookie "language=%{lang}e; path=/;" env=lang
Set Cookie based on Request. This code sends the Set-Cookie header to create a cookie on the client with the value of a matching item in 2nd parentheses.
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)(de|es|fr|it|ja|ru|en)/$ - [co=lang:$2:.yourserver.com:7200:/]

20. Send Custom Headers

Header set P3P "policyref=\"http://www.askapache.com/w3c/p3p.xml\""
Header set X-Pingback "http://www.askapache.com/xmlrpc.php"
Header set Content-Language "en-US"
Header set Vary "Accept-Encoding"

21. Blocking request based on User-Agent Header

SetEnvIfNoCase ^User-Agent$ .*(craftbot|download|extract|stripper|sucker|ninja|clshttp|webspider|leacher|collector|grabber|webpictures) HTTP_SAFE_BADBOT
SetEnvIfNoCase ^User-Agent$ .*(libwww-perl|aesop_com_spiderman) HTTP_SAFE_BADBOT
Deny from env=HTTP_SAFE_BADBOT


Thursday, September 26, 2013

Change style of html Tag on mouseenter and mouseleave by Jquery

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Change style of html Tag on mouseenter and mouseleave by Jquery</title>
<style>
p {
color: green;
}
</style>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<a href="#">Move the mouse over a paragraph.</a>
<a href="#">
Like this one or the one above.</a>
<script>
$( "p" )
.on( "mouseenter", function() {
$( this ).css({
"background-color": "balck",
"font-weight": "bolder"
});
})
.on( "mouseleave", function() {
var styles = {
backgroundColor : "#fds",
fontWeight: ""
};
$( this ).css( styles );
});
</script>
</body>
</html>

Tuesday, September 24, 2013

Convert Datatable To XML in C#



public static string ConvertDatatableToXML(DataTable dt)
    {
        MemoryStream str = new MemoryStream();
        dt.WriteXml(str, true);
        str.Seek(0, SeekOrigin.Begin);
        StreamReader sr = new StreamReader(str);
        string xmlstr;
        xmlstr = sr.ReadToEnd();
        return (xmlstr);
    }

Paging With Scrolling in datalist asp.net

aspx page

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CS.aspx.cs" Inherits="CS" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

<script type="text/javascript">
    var pageIndex = 1;
    var pageCount;
   function test() {
// if you load with paging then remove comment below
        //if ($(window).scrollTop() == $(document).height() - $(window).height()) {
            GetRecords();
        }
    //});
    function GetRecords() {
        pageIndex++;
        if (pageIndex == 2 || pageIndex <= pageCount) {
            $("#loader").show();
            $.ajax({
                type: "POST",
                url: "test.aspx/GetCustomers",
                data: '{pageIndex: ' + pageIndex + '}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: OnSuccess,
                failure: function (response) {
                    alert(response.d);
                },
                error: function (response) {
                    alert(response.d);
                }
            });
        }
    }
    function OnSuccess(response) {
        var xmlDoc = $.parseXML(response.d);
        var xml = $(xmlDoc);
        pageCount = parseInt(xml.find("Table1").eq(0).find("TotalRows").text());
        //alert(pageCount);
        var customers = xml.find("Table");
        customers.each(function () {
            var customer = $(this);
            var table = $("#dvCustomers table").eq(0).clone(true);
            $(".CityName", table).html(customer.find("CityName").text());
            $("#dvCustomers").append(table).append("<br />");
        });
        $("#loader").hide();
    }
    </script>


</head>
<body style="font-family: Arial; font-size: 10pt">
    <form id="form1" runat="server">
<table>
        <tr>
            <td>
                <div id="dvCustomers">
                    <asp:Repeater ID="rptCustomers" runat="server">
                        <ItemTemplate>
                            <table cellpadding="2" cellspacing="0" border="1" style="width: 200px; height: 100px;
                                border: dashed 2px #04AFEF; background-color: #B0E2F5">
                                <tr>
                                    <td>
                                        <b><u><span class="CityName">
                                            <%# Eval("CityName")%></span></u></b>
                                    </td>
                                </tr>
                               
                            </table>
                            <br />
                        </ItemTemplate>
                    </asp:Repeater>
                   
                    
                </div>
            </td>
           
        </tr>
        <tr>
            <td>
                <input type="button" onclick="test();" value="Load" />
            </td>
        </tr>
        <tr>
            <td valign="bottom">
                <img id="loader" alt="" src="images/ajax-loader.gif" style="display: none" />
            </td>
        </tr>
    </table>
    </form>
</body>
</html>







****************************************************************
cs file 





using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Services;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.IO;




public partial class test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //int pageIndex = 1;
            rptCustomers.DataSource = GetCity(1);
            rptCustomers.DataBind();
          
        }
    }

    public static DataSet GetCity(int pageIndex)
    {
//call procedure here
        DataSet ds = new DataSet();
        ds = BusinessLayer.Search.Test(pageIndex, 10);
       
        return ds;
    }

    [WebMethod]
    public static string GetCustomers(int pageIndex)
    {
        System.Threading.Thread.Sleep(2000);
        string dtsrt = GetCity(pageIndex).GetXml();
        return dtsrt;
    }
    public static string ConvertDatatableToXML(DataTable dt)
    {
        MemoryStream str = new MemoryStream();
        dt.WriteXml(str, true);
        str.Seek(0, SeekOrigin.Begin);
        StreamReader sr = new StreamReader(str);
        string xmlstr;
        xmlstr = sr.ReadToEnd();
        return (xmlstr);
    }
   
  
}

//create procedure whitch give result in  page

/*
[dbo].[Test]5,10
*/
ALTER PROC [dbo].[Test]
    @PageNo INT ,
    @ItemsPerPage INT
   
AS
BEGIN
    DECLARE
    @StartIdx int,
    @EndIdx INT
   
    IF @PageNo < 1 SET @PageNo = 1
    IF @ItemsPerPage < 1 SET @ItemsPerPage = 10
    SET @StartIdx = (@PageNo -1) * @ItemsPerPage + 1
    SET @EndIdx = (@StartIdx + @ItemsPerPage) - 1
    SELECT * FROM
    (SELECT  ROW_NUMBER() OVER(ORDER BY CityName) AS Row,
                CityName
            FROM Master.City
          
    ) AS tbl WHERE  Row >= + CONVERT(VARCHAR(9), @StartIdx)
    AND Row < = + CONVERT(varchar(9), @EndIdx)
   
   
    --total page cout
    SELECT COUNT(*)/@ItemsPerPage AS 'TotalRows' FROM Master.City
   
END

Sunday, September 22, 2013

Encapsulation

Encapsulation - is the ability of an object to hide its data and methods from the rest of the world. It is one of the fundamental principles of OOPs.

Say we create a class, named Calculations. This class may contain a few members in the form of properties, events, fields or methods. Once the class is created, we may instantiate the class by creating an object out of it. The object acts as an instance of this class, the members of the class are not exposed to the outer world directly, rather, they are encapsulated by the class.
Example

Public class Calculations
{
  private void fnMultiply(int x, int y)
  {
  return x * y;
  }
}
...
...
Calculations obj;
int Result;
Result = obj.fnMultiply(5,10);

3 tier architecture example in asp.net with C#

ASPX page

<table>
        <tr>
            <td colspan="2">
                <asp:Label ID="lblMsg" runat="server" Text="" ForeColor="Red"></asp:Label>
            </td>
        </tr>
        <tr>
            <td>
                Name :
            </td>
            <td>
                <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="btnAdd_Click" />
            </td>
            <td>
                <asp:Button ID="btnBack" runat="server" Text="Back" />
            </td>
        </tr>
    </table>

**************************************************************************

cs file of aspx page


using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
//call class file here
        Datatbl objData = new Datatbl();
        objData.tblId = "";
        objData.tblName = txtName.Text;

        DAOtbl objDAO = new DAOtbl();
        objDAO.insert(objData);
    }
}

*****************************************************************
now add class file Datatbl.cs



using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public class Datatbl
{
    private string id;
    private string name;

    public string tblId
    {
        get
        {
            return id;
        }
        set
        {
            id = value;
        }
    }

    public string tblName
    {
        get
        {
            return name;
        }
        set
        {
            name = value;
        }
    }
}

*************************************************************************
Now Establish connection Database.cs



using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public class Database
{
    public static SqlConnection connect()
    {
        SqlConnection con1 = new SqlConnection();
        con1.ConnectionString = "Data Source=.\\SQLExpress;AttachDbFileName=|DataDirectory|Database1.mdf;Integrated Security=True;User Instance=True;";
        return con1;
    }
}



*****************************************************************

Logic of get data,delete,update DAOtbl.cs


using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public class DAOtbl
{
    SqlConnection con = null;
    SqlCommand cmd = null;
    SqlDataAdapter adp = null;
    DataTable dt = null;
    string query = "";

    public Boolean isDuplicate(string name)
    {
        query = "SELECT COUNT(*) FROM tbl WHERE Name=@Name";
        con = Database.connect();
        cmd = new SqlCommand(query, con);
        cmd.Parameters.AddWithValue("@Name", name);

        con.Open();
        int count = Convert.ToInt16(cmd.ExecuteScalar());
        con.Close();
        if (count == 0)
            return false;
        return true;
    }

    public Boolean insert(Datatbl obj)
    {
        query = "INSERT INTO tbl VALUES (@Name)";
        con = Database.connect();
        cmd = new SqlCommand(query, con);
        cmd.Parameters.AddWithValue("@Name", obj.tblName);

        con.Open();
        int noOfRowsAffected = cmd.ExecuteNonQuery();
        con.Close();

        if (noOfRowsAffected == 1)
            return true;
        return false;
    }

    public Boolean update(Datatbl obj)
    {
        query = "UPDATE tbl SET Name=@Name WHERE Id=@Id";
        con = Database.connect();
        cmd = new SqlCommand(query, con);
        cmd.Parameters.AddWithValue("@Id", obj.tblId);
        cmd.Parameters.AddWithValue("@Name", obj.tblName);

        con.Open();
        int noOfRowsAffected = cmd.ExecuteNonQuery();
        con.Close();

        if (noOfRowsAffected == 1)
            return true;
        return false;
    }

    public Boolean delete(string id)
    {
        query = "DELETE FROM tbl WHERE Id=@Id";
        con = Database.connect();
        cmd = new SqlCommand(query, con);
        cmd.Parameters.AddWithValue("@Id", id);

        con.Open();
        int noOfRowsAffected = cmd.ExecuteNonQuery();
        con.Close();

        if (noOfRowsAffected == 1)
            return true;
        return false;
    }

    public Datatbl getDataById(string id)
    {
        query = "SELECT * FROM tbl WHERE Id=@Id";
        con = Database.connect();
        cmd = new SqlCommand(query, con);
        cmd.Parameters.AddWithValue("@Id", id);

        dt = new DataTable();
        adp = new SqlDataAdapter(cmd);

        con.Open();
        adp.Fill(dt);
        con.Close();

        Datatbl dataObj = null;
        if (dt != null && dt.Rows.Count == 1)
        {
            dataObj = new Datatbl();
            dataObj.tblId = dt.Rows[0]["Id"].ToString();
            dataObj.tblName = dt.Rows[0]["Name"].ToString();
        }
        return dataObj;
    }

    public DataTable getData()
    {
        query = "SELECT * FROM tbl";
        con = Database.connect();
        cmd = new SqlCommand(query, con);
        dt = new DataTable();
        adp = new SqlDataAdapter(cmd);

        con.Open();
        adp.Fill(dt);
        con.Close();

        return dt;
    }
}

Thursday, September 19, 2013

Saturday, September 14, 2013

limit text string in Eval asp.net

<%#Eval("MyText").ToString().Length <= 30 ? Eval("MyText") : Eval("MyText").ToString().Substring(0, 30)+"..."%> 

Tuesday, September 3, 2013

javascript set to uppercase , Lowerase, Capitalize

Upper case

 <script>
  var str="Hello world!";
  document.write(str.toUpperCase());
</script>

Lower case

 <script>
  var str="Hello world!";
  document.write(str.toLowerCase());
</script>

Capitalize

function toTitleCase(str)
{
    return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}

Trim a string in JavaScript

String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g, '');};

String.prototype.ltrim=function(){return this.replace(/^\s+/,'');};

String.prototype.rtrim=function(){return this.replace(/\s+$/,'');};

String.prototype.fulltrim=function(){return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,'').replace(/\s+/g,' ');};
 
 

C# Copy a file to another location with a different name

System.IO.File.Copy(oldPathAndName, newPathAndName);

Monday, September 2, 2013

Get Table from Word Document Asp.Net C#

for (int t = 1; t < doc.Tables.Count; t++)
        {
            DataTable dt = new DataTable();
            DataRow dr = dt.NewRow();
            int col = doc.Tables[t].Columns.Count;
            int row = doc.Tables[t].Rows.Count;
            for (int i = 1; i <= col; i++)
            {
                                   dt.Columns.Add(doc.Tables[t].Columns[i].Cells[1].Range.Text);
              }
               

            }
            for (int r = 2; r <= row; r++)
            {
                dr = dt.NewRow();
                dt.Rows.Add(dr);
                for (int c = 1; c <= col; c++)
                {
                                  dr[doc.Tables[t].Columns[c].Cells[1].Range.Text] = doc.Tables[t].Rows[r].Cells[c].Range.Text.Trim();
                    }
                                   
                }
            }

        }

Opps Part 1 : Abstraction

  Abstraction in C# is a fundamental concept of object-oriented programming (OOP) that allows developers t...