Showing posts with label reading. Show all posts
Showing posts with label reading. Show all posts

Thursday, 31 January 2013

Reading Registry Value using JavaScript



Root Key Name
Abbreviation
HKEY_CURRENT_USER
HKCU
HKEY_LOCAL_MACHINE
HKLM
HKEY_CLASSES_ROOT
HKCR
HKEY_USERS
HKEY_USERS
HKEY_CURRENT_CONFIG
HKEY_CURRENT_CONFIG

<!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>
        <title>Reading Registry Value</title>
        <script type="text/javascript">
            function readValue() {
                var WshShell = new ActiveXObject("WScript.Shell");
                var value = WshShell.RegRead("HKCU\\Software\\Microsoft\\FTP\\Use PASV");
                document.write("Value of Use PASV: " + value);
            }
        </script>
    </head>
    <body onload="javascript: readValue()">

    </body>
</html>

Note: This code works only in Internet Explorer.

Wednesday, 30 January 2013

Reading data from CSV File using JavaScript



<!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>
        <title>Reading Data from CSV File</title>
        <style type="text/css">
            div
            {
                float: left;
                width: 250px;
            }
        </style>
        <script type="text/javascript">
            function readCSVFile() {
                var csvData = new Array();
                var csvFilePath = "F:\\Data.csv";

                var fso = new ActiveXObject('Scripting.FileSystemObject');
                var iStream = fso.OpenTextFile(csvFilePath, 1, true, 0);
                for (var n = 0; !iStream.AtEndOfStream; n++) {
                    csvData[n] = iStream.ReadLine();
                    showData(csvData[n]);
                }
                iStream.Close();
            }

            function showData(data) {
                var csvData = data.split(",");
                document.getElementById('firstNames').innerHTML += "<br />" + csvData[0];
                document.getElementById('middleNames').innerHTML += "<br />" + csvData[1];
                document.getElementById('lastNames').innerHTML += "<br />" + csvData[2];
            }
        </script>
    </head>
    <body onload="javascript: readCSVFile()">
        <div id="firstNames"><b><i>First Names:</i></b></div>
        <div id="middleNames"><b><i>Middle Names:</i></b></div>
        <div id="lastNames"><b><i>Last Names:</i></b></div>
    </body>
</html>

Note: This code works only in Internet Explorer

Reading Data from CSV File using C#


Step 1: Create New Project (Windows Forms Application).
Step 2: Add “System.IO” namespace.
Step 3: Create the form as follows.

Step 4: Write the following code.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace ReadingCSV
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void buttonRead_Click(object sender, EventArgs e)
        {
            DataTable dataTable = new DataTable();
            dataTable.Columns.Add("First Name");
            dataTable.Columns.Add("Last Name");
            dataTable.Columns.Add("Age");
            string filePath = textBoxFilePath.Text;
            StreamReader streamReader = new StreamReader(filePath);
            string[] totalData = new string[File.ReadAllLines(filePath).Length];
            totalData = streamReader.ReadLine().Split(',');
            while (!streamReader.EndOfStream)
            {
                totalData = streamReader.ReadLine().Split(',');
                dataTable.Rows.Add(totalData[0], totalData[1], totalData[2]);
            }
            dataGridViewStudents.DataSource = dataTable;
        }
    }
}

Step 5: Output