使用html/javascript阅读txt文件 [英] reading a txt file using html/javascript

查看:175
本文介绍了使用html/javascript阅读txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我想将txt文件的内容显示到文本框中,这是我的asp.net应用程序之一
.那我该怎么办
我在互联网上搜索,我得到了此代码
我拿了一个脚本标签并放置了此代码

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.

推荐答案

代替文本框,您可以使用此一个
试试这个

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

希望这个答案能对您有所帮助
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


您好,我想知道仅使用javascript来显示文件内容是一项要求吗?
如果没有,则在aspx页上使用TextBox作为

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

然后在页面加载事件中输入此代码

受保护的void Page_Load(对象发送者,EventArgs e)
{
txtFile.Text = File.ReadAllText("myFile.txt");
}

希望对您有帮助.
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.


这篇关于使用html/javascript阅读txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆