Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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

C#
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.
Posted
Updated 6-May-17 8:22am

instead of textbox you can use this one
try this

<iframe id="txtviewer" height="400" width="800" src="filepath"></iframe>

hope this answer will help you
 
Share this answer
 
Hi, I want to know that is it a requirement to use only javascript to show the file content?
if not then use a TextBox on the aspx page as

<asp:TextBox ID="txtFile" runat="server"></asp:TextBox>

then on page load Event put this code

protected void Page_Load(object sender, EventArgs e)
{
txtFile.Text= File.ReadAllText("myFile.txt");
}

hope this will help you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900