reading a txt file using html/javascript

hello  every one
 
I one of my asp.net application i want to display the txt file content into textbox
. So how can i do it
i search in internet i got this code
I took a script tag and place this code
 

function read()
    {
//  var   file = fopen(getScriptPath("a.txt"), 0);
//  var   file_length = flength(file);
//  var   content = fread(file, file_length);
//document.getElementById("myDiv").innerText = content;
try
    {
 
        var fso  = new ActiveXObject(‘Scripting.FileSystemObject’);
         alert(‘ok’);
 
        var fh = fso.OpenTextFile(‘a.txt’,1);
        var contents = fh.ReadAll();
        fh.Close();
 
        alert(contents);
        //return contents;
    }
    catch (Exception)
    {
       alert(‘Cannot open file :(‘);
    }
 
}

 

the commented one is also not working nor the other one so can anyone guide me or give some suggestions.

check out below link,

you can’t use javascript because it will run on the client machine..

http://www.gridview.net/read-text-file-in-c-asp-net/

Hi,

You can’t read Files using JavaScript due to security reasons!

You have used ActiveX, but it won’t work other than IE browsers!

You can use Server Side Code(C#/VB) to read the file and update it to the textbox!

Hope it helps u…

HI,

check my blog post for reading clientside files.
http://rajudasa.blogspot.in/2010/10/firefox-parsing-client-side-xml-file.html

check reference sites there
to read from txt files.

Leave a Reply