How to create Windows Services in C#? Example.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using System.Timers;

namespace ScheduledService
{
    public partial class ScheduledService : ServiceBase
    {
        Timer timer = new Timer();
        public ScheduledService()
        {
            InitializeComponent();
        }
        protected override void OnStart(string[] args)
        {
            TraceService("start service");
            timer.Elapsed += new ElapsedEventHandler(OnElapsedTime);
            timer.Interval = 1000;
            timer.Enabled = true;
        }
        protected override void OnStop()
        {
            timer.Enabled = false;
            TraceService("stopping service");
        }
        private void OnElapsedTime(object source, ElapsedEventArgs e)
        {
            TraceService("Another entry at " + DateTime.Now);
        }
        private void TraceService(string content)
        {
            FileStream fs = new FileStream(@"d:\ScheduledService.txt", FileMode.OpenOrCreate, FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs);
            sw.BaseStream.Seek(0, SeekOrigin.End);
            sw.WriteLine(content);
            sw.Flush();
            sw.Close();
        }
    }
}

Share:

How to check excel Date Format using C#? Example.

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <style type="text/css">
        .auto-style1 {
            width: 50%;
        }
    </style>

</head>
<body>
    <form id="form1" runat="server">
 

    <table align="center" class="auto-style1">
        <tr>
            <td>
                <asp:FileUpload ID="FileUpload1" runat="server" Width="200px" />&nbsp;&nbsp;<asp:Button ID="Button1" runat="server" Style="margin-left: 0px" Text="Upload" OnClick="Button1_Click" /></td>
         
        </tr>
        <tr>
            <td>
                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
                    <Columns>
                        <asp:BoundField DataField="ID" HeaderText="ID" HtmlEncode="False" ReadOnly="True" />
                        <asp:BoundField DataField="NAME" HeaderText="NAME" HtmlEncode="False" ReadOnly="True" />
                        <asp:BoundField DataField="JOINDATE" HeaderText="JOINDATE" HtmlEncode="False" DataFormatString="{0:d}" ReadOnly="True" />
                    </Columns>


                </asp:GridView>
            </td>

        </tr>
    </table>
      </form>
</body>
</html>
-----------------------------------------------
using Microsoft.Office.Interop.Excel;
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Excel = Microsoft.Office.Interop.Excel.Application;
public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // processExcel("D:\\Book1.xlsx");
    }
    private void processExcel(string filename)
    {
        Application xlApp;
        Workbook xlWorkBook;
        Worksheet xlWorkSheet;

        var missing = System.Reflection.Missing.Value;

        xlApp = new ApplicationClass();
        xlWorkBook = xlApp.Workbooks.Open(filename);
        //xlWorkBook = xlApp.Workbooks.Open(filename, false, true, missing, missing, missing, true, XlPlatform.xlWindows, '\t', false, false, 0, false, true, 0);
        xlWorkSheet = (Worksheet)xlWorkBook.Worksheets.get_Item(1);

        Range xlRange = xlWorkSheet.UsedRange;
        Array myValues = (Array)xlRange.Cells.Value2;



        int vertical = myValues.GetLength(0);
        int horizontal = myValues.GetLength(1);

        System.Data.DataTable dt = new System.Data.DataTable();
        DateTime tempD = new DateTime();
        //if (DateTime.TryParse(myValues.GetValue(3, 3).ToString(), out tempD))
        //{

        //}
        // must start with index = 1
        // get header information
        for (int i = 1; i <= horizontal; i++)
        {
            dt.Columns.Add(new DataColumn(myValues.GetValue(1, i).ToString()));
        }

        // Get the row information
        for (int a = 2; a <= vertical; a++)
        {


            object[] poop = new object[horizontal];
            for (int b = 1; b <= horizontal; b++)
            {
                try
                {
                    poop[b - 1] = myValues.GetValue(a, b);
                    if (poop[2] != null)
                    {

                        double d = double.Parse(myValues.GetValue(a, b).ToString());
                        // DateTime conv = DateTime.FromOADate(d);
                        DateTime conv = DateTime.FromOADate(d);
                        //string date = conv.Date.ToString();
                        //string date = conv.ToShortDateString();
                        // poop[b - 1] = date;
                        poop[b - 1] = conv;
                    }
                    else
                    {
                        poop[b - 1] = myValues.GetValue(a, b);
                    }
                }
                catch (Exception ex)
                {
                    poop[b - 1] = "DateTime is not currect format !";
                }

            }
            DataRow row = dt.NewRow();
            row.ItemArray = poop;
            dt.Rows.Add(row);
        }
        //
        //foreach (DataRow dr in dt.Rows)
        //{
        //    double d = double.Parse(dr["JoinDate"].ToString());
        //    DateTime conv = DateTime.FromOADate(d);
        //    string date = conv.Date.ToString();


        //}

        // assign table to default data grid view

        GridView1.DataSource = dt;
        GridView1.DataBind();
        xlWorkBook.Close(true, missing, missing);
        xlApp.Quit();

        releaseObject(xlWorkSheet);
        releaseObject(xlWorkBook);
        releaseObject(xlApp);
    }

    private void releaseObject(object obj)
    {
        try
        {
            System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
            obj = null;
        }
        catch (Exception ex)
        {
            obj = null;
            Response.Write("Unable to release the Object " + ex.ToString());
        }
        finally
        {
            GC.Collect();
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string FilePath = FileUpload1.PostedFile.FileName;
        //string path = @"D:\Book1.xlsx";
        // string path = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);

        processExcel(FilePath);
    }
}
Share:

How to read files data and save in directory using C#? Example.

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default3 : System.Web.UI.Page
{
    SqlConnection CN = new SqlConnection(@"SERVER=172.29.57.158\sql2012;Database=eMAAS;User ID=sa;Password=Mind1234");
    protected void Page_Load(object sender, EventArgs e)
    {
        Label2.Visible = false;
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string ext;
        string[] allfiles = System.IO.Directory.GetFiles(TextBox1.Text, "*.*", System.IO.SearchOption.AllDirectories);
        foreach (var file in allfiles)
        {
            FileInfo info = new FileInfo(file);
           

            string name = info.Name.ToString();
            ext =info.Extension.ToString();
           
            if (ext == ".ldb" || ext == ".LDB")
            {
                ext = "Microsoft Access Record - Locking Information";
            }
            else if (ext == ".dbf" || ext == ".DBF")
            {
                ext = "DBF File";
            }
            else if (ext == ".xml" || ext == ".XML")
            {
                ext = "XML Document";
            }
            else if (ext == ".csv" || ext == ".CSV")
            {
                ext = "Microsoft Excel Comma Separated Values File";
            }
           
            else if (ext == ".CTL" || ext == ".ctl")
            {
                ext = "CTL File";
            }
            else if (ext == ".eds" || ext == ".EDS")
            {
                ext = "EDS File";
            }
            else if (ext == ".dts" || ext == ".DTS")
            {
                ext = "DTS File";
            }
            else if (ext == ".gfx" || ext == ".GFX")
            {
                ext = "GFX File";
            }
            else if (ext == ".pdf" || ext == ".PDF")
            {
                ext = "PDF File";
            }
            else if (ext == ".lnk" || ext == ".LNK")
            {
                ext = "LNK File";
            }
            else if (ext == ".txt" || ext == ".TXT")
            {
                ext = "TEXT File";
            }
            else if (ext == ".exe" || ext == ".EXE")
            {
                ext = "EXE File";
            }
            else if (ext == ".log" || ext == ".LOG")
            {
                ext = "LOG File";
            }
            else if (ext == ".dll" || ext == ".DLL")
            {
                ext = "DLL File";
            }
            else if (ext == ".gpd" || ext == ".GDP")
            {
                ext = "GPD File";
            }
            else if (ext == ".ppd" || ext == ".PPD")
            {
                ext = "PPD File";
            }
            else if (ext == ".prt" || ext == ".RPT")
            {
                ext = "PRT File";
            }
            else if (ext == ".dat" || ext == ".DAT")
            {
                ext = "DAT File";
            }
            else if (ext == ".ini" || ext == ".INI")
            {
                ext = "INI File";
            }

            else if (ext == ".tab" || ext == ".TAB")
            {
                ext = "TAB File";
            }

            else if (ext == ".rtp" || ext == ".RPT")
            {
                ext = "RPT File";
            }
            else if (ext == ".ZPP" || ext == ".zpp")
            {
                ext = "ZPP File";
            }
            else if (ext == ".BLD" || ext == ".sld")
            {
                ext = "BLD File";
            }
            else if (ext == ".zip" || ext == ".ZIP")
            {
                ext = "ZIP File";
            }
            else if (ext == ".cmp" || ext == ".CMP")
            {
                ext = "CMP File";
            }
         
            else if (ext == ".zrt" || ext == ".ZRT")
            {
                ext = "ZRT File";
            }

            else if (ext == ".rdl" || ext == ".RDL")
            {
                ext = "RDL File";
            }

            else if (ext == ".data")
            {
                ext = "DATA File";
            }

         
            else if (ext == ".DBI" || ext == ".dbi")
            {
                ext = "DBI File";
            }
            else if (ext == "")
            {
                ext = "File";
            }
            else if (ext == ".rpt" || ext == ".RPT")
            {
                ext = "RPT File";
            }
            else if (ext == ".rsv" || ext == ".RSV")
            {
                ext = "RSV File";
            }
            else if (ext == ".pfe" || ext == ".PFE")
            {
                ext = "PFE File";

            }
            else if (ext == ".sec" || ext == ".SEC")
            {
                ext = "SEC File";
            }
            else if (ext == ".als" || ext == ".ALS")
            {
                ext = "SEC File";
            }
            else if (ext == ".act" || ext == ".ACT")
            {
                ext = "ACT File";
            }
            else if (ext == ".mdb" || ext == ".MDB")
            {
                ext = "Microsoft Access Database";
            }
            else if (ext == ".csv" || ext == ".CSV")
            {
                ext = "Microsoft Excel";
            }
            else if (ext == ".vba" || ext == ".VBA")
            {
                ext = "VBA File";
            }
            else if (ext == ".ARS" || ext == ".ars")
            {
                ext = "ARS File";
            }
            else if (ext == ".AML" || ext == ".aml")
            {
                ext = "AML File";
            }
            else if (ext == ".rsv" || ext == ".RVS")
            {
                ext = "RVS File";
            }
            else if (ext == ".ARX" || ext == ".arx")
            {
                ext = "ARX File";
            }
            else if (ext == ".ARS" || ext == ".ars")
            {
                ext = "ARS File";
            }
            else if (ext == ".BIN" || ext == ".bin")
            {
                ext = "BIN File";
            }
            else if (ext == ".REE" || ext == ".ree")
            {
                ext = "REE File";
            }
            else if (ext == ".idx" || ext == ".IDX")
            {
                ext = "SQL Server Replication Snapshot Index Script";
            }
            else if (ext == ".CEL" || ext == ".CEL")
            {
                ext = "CEL File";
            }

            else if (ext == ".tmp" || ext == ".TMP")
            {
                ext = "TEP File";
            }
            else if (ext == ".ARI" || ext == ".ari")
            {
                ext = "ARI File";
            }
            else if (ext == ".ldf" || ext == ".LDF")
            {
                ext = "SQL Server Database Transaction Log File";
            }

            else if (ext == ".mdf" || ext == ".MDF")
            {
                ext = "SQL Server Database Primary Data File";
            }
            else if (ext == ".bak" || ext == ".BAK")
            {
                ext = "BAK File";
            }
            else if (ext == ".mdb" || ext == ".MDB")
            {
                ext = "Microsoft Access Database";
            }

            else if (ext == ".LDB")
            {

                ext = "Microsoft Access Record - Locking Information";
            }
            else if (ext == ".xlsx" || ext == ".xltx" || ext == ".xlt")
            {

                ext = "Microsoft Excel Worksheet";
            }

            string qry = "insert into eMAAS_Tbl_DirFileInfo (FileNames,Ext) values('" + name.Replace("'", "`").Trim() + "','" + ext.Trim() + "')";
            SqlCommand SqlCom = new SqlCommand(qry, CN);
            CN.Open();
            SqlCom.ExecuteNonQuery();
            CN.Close();
        }
        Label2.Text = "Successfully..";
        TextBox1.Text = "";
        Label2.Visible = true;
    }



    protected void Button3_Click(object sender, EventArgs e)
    {
        string qry = "truncate table eMAAS_Tbl_DirFileInfo";
        SqlCommand SqlCom = new SqlCommand(qry, CN);
        CN.Open();
        SqlCom.ExecuteNonQuery();
        CN.Close();
    }

}
Share:

Monday, 8 January 2018

How to create Windows Services in C#? Example.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using System.Timers;

namespace ScheduledService
{
    public partial class ScheduledService : ServiceBase
    {
        Timer timer = new Timer();
        public ScheduledService()
        {
            InitializeComponent();
        }
        protected override void OnStart(string[] args)
        {
            TraceService("start service");
            timer.Elapsed += new ElapsedEventHandler(OnElapsedTime);
            timer.Interval = 1000;
            timer.Enabled = true;
        }
        protected override void OnStop()
        {
            timer.Enabled = false;
            TraceService("stopping service");
        }
        private void OnElapsedTime(object source, ElapsedEventArgs e)
        {
            TraceService("Another entry at " + DateTime.Now);
        }
        private void TraceService(string content)
        {
            FileStream fs = new FileStream(@"d:\ScheduledService.txt", FileMode.OpenOrCreate, FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs);
            sw.BaseStream.Seek(0, SeekOrigin.End);
            sw.WriteLine(content);
            sw.Flush();
            sw.Close();
        }
    }
}

How to check excel Date Format using C#? Example.

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <style type="text/css">
        .auto-style1 {
            width: 50%;
        }
    </style>

</head>
<body>
    <form id="form1" runat="server">
 

    <table align="center" class="auto-style1">
        <tr>
            <td>
                <asp:FileUpload ID="FileUpload1" runat="server" Width="200px" />&nbsp;&nbsp;<asp:Button ID="Button1" runat="server" Style="margin-left: 0px" Text="Upload" OnClick="Button1_Click" /></td>
         
        </tr>
        <tr>
            <td>
                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
                    <Columns>
                        <asp:BoundField DataField="ID" HeaderText="ID" HtmlEncode="False" ReadOnly="True" />
                        <asp:BoundField DataField="NAME" HeaderText="NAME" HtmlEncode="False" ReadOnly="True" />
                        <asp:BoundField DataField="JOINDATE" HeaderText="JOINDATE" HtmlEncode="False" DataFormatString="{0:d}" ReadOnly="True" />
                    </Columns>


                </asp:GridView>
            </td>

        </tr>
    </table>
      </form>
</body>
</html>
-----------------------------------------------
using Microsoft.Office.Interop.Excel;
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Excel = Microsoft.Office.Interop.Excel.Application;
public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // processExcel("D:\\Book1.xlsx");
    }
    private void processExcel(string filename)
    {
        Application xlApp;
        Workbook xlWorkBook;
        Worksheet xlWorkSheet;

        var missing = System.Reflection.Missing.Value;

        xlApp = new ApplicationClass();
        xlWorkBook = xlApp.Workbooks.Open(filename);
        //xlWorkBook = xlApp.Workbooks.Open(filename, false, true, missing, missing, missing, true, XlPlatform.xlWindows, '\t', false, false, 0, false, true, 0);
        xlWorkSheet = (Worksheet)xlWorkBook.Worksheets.get_Item(1);

        Range xlRange = xlWorkSheet.UsedRange;
        Array myValues = (Array)xlRange.Cells.Value2;



        int vertical = myValues.GetLength(0);
        int horizontal = myValues.GetLength(1);

        System.Data.DataTable dt = new System.Data.DataTable();
        DateTime tempD = new DateTime();
        //if (DateTime.TryParse(myValues.GetValue(3, 3).ToString(), out tempD))
        //{

        //}
        // must start with index = 1
        // get header information
        for (int i = 1; i <= horizontal; i++)
        {
            dt.Columns.Add(new DataColumn(myValues.GetValue(1, i).ToString()));
        }

        // Get the row information
        for (int a = 2; a <= vertical; a++)
        {


            object[] poop = new object[horizontal];
            for (int b = 1; b <= horizontal; b++)
            {
                try
                {
                    poop[b - 1] = myValues.GetValue(a, b);
                    if (poop[2] != null)
                    {

                        double d = double.Parse(myValues.GetValue(a, b).ToString());
                        // DateTime conv = DateTime.FromOADate(d);
                        DateTime conv = DateTime.FromOADate(d);
                        //string date = conv.Date.ToString();
                        //string date = conv.ToShortDateString();
                        // poop[b - 1] = date;
                        poop[b - 1] = conv;
                    }
                    else
                    {
                        poop[b - 1] = myValues.GetValue(a, b);
                    }
                }
                catch (Exception ex)
                {
                    poop[b - 1] = "DateTime is not currect format !";
                }

            }
            DataRow row = dt.NewRow();
            row.ItemArray = poop;
            dt.Rows.Add(row);
        }
        //
        //foreach (DataRow dr in dt.Rows)
        //{
        //    double d = double.Parse(dr["JoinDate"].ToString());
        //    DateTime conv = DateTime.FromOADate(d);
        //    string date = conv.Date.ToString();


        //}

        // assign table to default data grid view

        GridView1.DataSource = dt;
        GridView1.DataBind();
        xlWorkBook.Close(true, missing, missing);
        xlApp.Quit();

        releaseObject(xlWorkSheet);
        releaseObject(xlWorkBook);
        releaseObject(xlApp);
    }

    private void releaseObject(object obj)
    {
        try
        {
            System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
            obj = null;
        }
        catch (Exception ex)
        {
            obj = null;
            Response.Write("Unable to release the Object " + ex.ToString());
        }
        finally
        {
            GC.Collect();
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string FilePath = FileUpload1.PostedFile.FileName;
        //string path = @"D:\Book1.xlsx";
        // string path = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);

        processExcel(FilePath);
    }
}

How to read files data and save in directory using C#? Example.

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default3 : System.Web.UI.Page
{
    SqlConnection CN = new SqlConnection(@"SERVER=172.29.57.158\sql2012;Database=eMAAS;User ID=sa;Password=Mind1234");
    protected void Page_Load(object sender, EventArgs e)
    {
        Label2.Visible = false;
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string ext;
        string[] allfiles = System.IO.Directory.GetFiles(TextBox1.Text, "*.*", System.IO.SearchOption.AllDirectories);
        foreach (var file in allfiles)
        {
            FileInfo info = new FileInfo(file);
           

            string name = info.Name.ToString();
            ext =info.Extension.ToString();
           
            if (ext == ".ldb" || ext == ".LDB")
            {
                ext = "Microsoft Access Record - Locking Information";
            }
            else if (ext == ".dbf" || ext == ".DBF")
            {
                ext = "DBF File";
            }
            else if (ext == ".xml" || ext == ".XML")
            {
                ext = "XML Document";
            }
            else if (ext == ".csv" || ext == ".CSV")
            {
                ext = "Microsoft Excel Comma Separated Values File";
            }
           
            else if (ext == ".CTL" || ext == ".ctl")
            {
                ext = "CTL File";
            }
            else if (ext == ".eds" || ext == ".EDS")
            {
                ext = "EDS File";
            }
            else if (ext == ".dts" || ext == ".DTS")
            {
                ext = "DTS File";
            }
            else if (ext == ".gfx" || ext == ".GFX")
            {
                ext = "GFX File";
            }
            else if (ext == ".pdf" || ext == ".PDF")
            {
                ext = "PDF File";
            }
            else if (ext == ".lnk" || ext == ".LNK")
            {
                ext = "LNK File";
            }
            else if (ext == ".txt" || ext == ".TXT")
            {
                ext = "TEXT File";
            }
            else if (ext == ".exe" || ext == ".EXE")
            {
                ext = "EXE File";
            }
            else if (ext == ".log" || ext == ".LOG")
            {
                ext = "LOG File";
            }
            else if (ext == ".dll" || ext == ".DLL")
            {
                ext = "DLL File";
            }
            else if (ext == ".gpd" || ext == ".GDP")
            {
                ext = "GPD File";
            }
            else if (ext == ".ppd" || ext == ".PPD")
            {
                ext = "PPD File";
            }
            else if (ext == ".prt" || ext == ".RPT")
            {
                ext = "PRT File";
            }
            else if (ext == ".dat" || ext == ".DAT")
            {
                ext = "DAT File";
            }
            else if (ext == ".ini" || ext == ".INI")
            {
                ext = "INI File";
            }

            else if (ext == ".tab" || ext == ".TAB")
            {
                ext = "TAB File";
            }

            else if (ext == ".rtp" || ext == ".RPT")
            {
                ext = "RPT File";
            }
            else if (ext == ".ZPP" || ext == ".zpp")
            {
                ext = "ZPP File";
            }
            else if (ext == ".BLD" || ext == ".sld")
            {
                ext = "BLD File";
            }
            else if (ext == ".zip" || ext == ".ZIP")
            {
                ext = "ZIP File";
            }
            else if (ext == ".cmp" || ext == ".CMP")
            {
                ext = "CMP File";
            }
         
            else if (ext == ".zrt" || ext == ".ZRT")
            {
                ext = "ZRT File";
            }

            else if (ext == ".rdl" || ext == ".RDL")
            {
                ext = "RDL File";
            }

            else if (ext == ".data")
            {
                ext = "DATA File";
            }

         
            else if (ext == ".DBI" || ext == ".dbi")
            {
                ext = "DBI File";
            }
            else if (ext == "")
            {
                ext = "File";
            }
            else if (ext == ".rpt" || ext == ".RPT")
            {
                ext = "RPT File";
            }
            else if (ext == ".rsv" || ext == ".RSV")
            {
                ext = "RSV File";
            }
            else if (ext == ".pfe" || ext == ".PFE")
            {
                ext = "PFE File";

            }
            else if (ext == ".sec" || ext == ".SEC")
            {
                ext = "SEC File";
            }
            else if (ext == ".als" || ext == ".ALS")
            {
                ext = "SEC File";
            }
            else if (ext == ".act" || ext == ".ACT")
            {
                ext = "ACT File";
            }
            else if (ext == ".mdb" || ext == ".MDB")
            {
                ext = "Microsoft Access Database";
            }
            else if (ext == ".csv" || ext == ".CSV")
            {
                ext = "Microsoft Excel";
            }
            else if (ext == ".vba" || ext == ".VBA")
            {
                ext = "VBA File";
            }
            else if (ext == ".ARS" || ext == ".ars")
            {
                ext = "ARS File";
            }
            else if (ext == ".AML" || ext == ".aml")
            {
                ext = "AML File";
            }
            else if (ext == ".rsv" || ext == ".RVS")
            {
                ext = "RVS File";
            }
            else if (ext == ".ARX" || ext == ".arx")
            {
                ext = "ARX File";
            }
            else if (ext == ".ARS" || ext == ".ars")
            {
                ext = "ARS File";
            }
            else if (ext == ".BIN" || ext == ".bin")
            {
                ext = "BIN File";
            }
            else if (ext == ".REE" || ext == ".ree")
            {
                ext = "REE File";
            }
            else if (ext == ".idx" || ext == ".IDX")
            {
                ext = "SQL Server Replication Snapshot Index Script";
            }
            else if (ext == ".CEL" || ext == ".CEL")
            {
                ext = "CEL File";
            }

            else if (ext == ".tmp" || ext == ".TMP")
            {
                ext = "TEP File";
            }
            else if (ext == ".ARI" || ext == ".ari")
            {
                ext = "ARI File";
            }
            else if (ext == ".ldf" || ext == ".LDF")
            {
                ext = "SQL Server Database Transaction Log File";
            }

            else if (ext == ".mdf" || ext == ".MDF")
            {
                ext = "SQL Server Database Primary Data File";
            }
            else if (ext == ".bak" || ext == ".BAK")
            {
                ext = "BAK File";
            }
            else if (ext == ".mdb" || ext == ".MDB")
            {
                ext = "Microsoft Access Database";
            }

            else if (ext == ".LDB")
            {

                ext = "Microsoft Access Record - Locking Information";
            }
            else if (ext == ".xlsx" || ext == ".xltx" || ext == ".xlt")
            {

                ext = "Microsoft Excel Worksheet";
            }

            string qry = "insert into eMAAS_Tbl_DirFileInfo (FileNames,Ext) values('" + name.Replace("'", "`").Trim() + "','" + ext.Trim() + "')";
            SqlCommand SqlCom = new SqlCommand(qry, CN);
            CN.Open();
            SqlCom.ExecuteNonQuery();
            CN.Close();
        }
        Label2.Text = "Successfully..";
        TextBox1.Text = "";
        Label2.Visible = true;
    }



    protected void Button3_Click(object sender, EventArgs e)
    {
        string qry = "truncate table eMAAS_Tbl_DirFileInfo";
        SqlCommand SqlCom = new SqlCommand(qry, CN);
        CN.Open();
        SqlCom.ExecuteNonQuery();
        CN.Close();
    }

}

Popular

Total Pageviews

Archive