StreamReader和文本文件问题 [英] StreamReader and text file problem

查看:51
本文介绍了StreamReader和文本文件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在网页上显示文本文件,下面的代码工作正常

并在网页上显示文本。但是,如果我使用(我需要)一个

主页,然后将代码放在一个使用主页面的webform中,那么它会显示单词''会议纪要''这是

文本的标题,位于下面代码的底部。在

主页中是否存在阻止此工作的内容?

干杯

ArtySin


<%@ Import Namespace =" System.IO" %>

< script language =" vb" runat =" server">

sub Page_Load(sender as Object,e as EventArgs)

Dim FILENAME as String = Server.MapPath(" minutes.txt")

将objStreamReader变暗为StreamReader

objStreamReader = File.OpenText(FILENAME)


昏暗contents as String = objStreamReader.ReadToEnd()

lblRawOutput.Text = contents


objStreamReader.Close()

end sub

< / script>

< b>会议纪要< / b>< br />

< asp:label runat =" server" ID = QUOT; lblRawOutput" />

I''m trying to display a text file on a web page and the code below works fine
and display the text on a webpage. However,if I use (as I need to) a
masterpage and then place the code in a webform that uses the masterpage all
it does is display the words ''Meeting minutes'' which is the header for the
text right at the bottom of the code below. Is there something in a
masterpage that prevents this working at all?
Cheers
ArtySin

<%@ Import Namespace="System.IO" %>
<script language="vb" runat="server">
sub Page_Load(sender as Object, e as EventArgs)

Dim FILENAME as String = Server.MapPath("minutes.txt")

Dim objStreamReader as StreamReader
objStreamReader = File.OpenText(FILENAME)

Dim contents as String = objStreamReader.ReadToEnd()
lblRawOutput.Text = contents

objStreamReader.Close()
end sub
</script>

<b>Meeting Minutes</b><br />
<asp:label runat="server" id="lblRawOutput" />

推荐答案

问题是使用母版页时路径无法正确解析。

试试这个:


Dim FILENAME为String = Server.MapPath("〜minutes.txt")

" ArtySin" < Ar ***** @ discuss.microsoft.com写信息

新闻:15 *********************** *********** @ microsof t.com ...
The problem is the path is not resolved properly when master pages are used.
Try this:

Dim FILENAME as String = Server.MapPath("~minutes.txt")
"ArtySin" <Ar*****@discussions.microsoft.comwrote in message
news:15**********************************@microsof t.com...

我正在尝试在网页上显示文本文件下面的代码工作

罚款

并在网页上显示文字。但是,如果我使用(我需要)一个

主页,然后将代码放在使用主页面的webform中

all

它会显示单词''Meeting minutes'',它是

文本的标题,位于下面代码的底部。在

主页中是否存在阻止此工作的内容?

干杯

ArtySin


<%@ Import Namespace =" System.IO" %>

< script language =" vb" runat =" server">

sub Page_Load(sender as Object,e as EventArgs)

Dim FILENAME as String = Server.MapPath(" minutes.txt")

将objStreamReader变暗为StreamReader

objStreamReader = File.OpenText(FILENAME)


昏暗contents as String = objStreamReader.ReadToEnd()


lblRawOutput.Text = contents


objStreamReader.Close()

end sub

< / script>


< b>会议纪要< / b>< br />

< asp:label runat =" server" ID = QUOT; lblRawOutput" />

I''m trying to display a text file on a web page and the code below works
fine
and display the text on a webpage. However,if I use (as I need to) a
masterpage and then place the code in a webform that uses the masterpage
all
it does is display the words ''Meeting minutes'' which is the header for the
text right at the bottom of the code below. Is there something in a
masterpage that prevents this working at all?
Cheers
ArtySin

<%@ Import Namespace="System.IO" %>
<script language="vb" runat="server">
sub Page_Load(sender as Object, e as EventArgs)

Dim FILENAME as String = Server.MapPath("minutes.txt")

Dim objStreamReader as StreamReader
objStreamReader = File.OpenText(FILENAME)

Dim contents as String = objStreamReader.ReadToEnd()
lblRawOutput.Text = contents

objStreamReader.Close()
end sub
</script>

<b>Meeting Minutes</b><br />
<asp:label runat="server" id="lblRawOutput" />



没有运气的斯科特。我试过了:

(~daily.txt")

(〜/ minutes.txt")

(〜/ pathname / minutes.txt" ;)


但这些都不起作用.....任何其他想法/

干杯

ArtySin


" Scott M."写道:
No luck with that Scott. I tried:
(~minutes.txt")
(~/minutes.txt")
(~/pathname/minutes.txt")

but none of these works at all ..... any other ideas/
Cheers
ArtySin

"Scott M." wrote:

问题是使用母版页时路径无法正确解决。

试试这个:


Dim FILENAME as String = Server.MapPath("〜minutes.txt")


" ArtySin" < Ar ***** @ discuss.microsoft.com写信息

新闻:15 *********************** *********** @ microsof t.com ...
The problem is the path is not resolved properly when master pages are used.
Try this:

Dim FILENAME as String = Server.MapPath("~minutes.txt")
"ArtySin" <Ar*****@discussions.microsoft.comwrote in message
news:15**********************************@microsof t.com...

我正在尝试在网页上显示文本文件下面的代码工作

罚款

并在网页上显示文字。但是,如果我使用(我需要)一个

主页,然后将代码放在使用主页面的webform中

all

它会显示单词''Meeting minutes'',它是

文本的标题,位于下面代码的底部。在

主页中是否存在阻止此工作的内容?

干杯

ArtySin


<%@ Import Namespace =" System.IO" %>

< script language =" vb" runat =" server">

sub Page_Load(sender as Object,e as EventArgs)

Dim FILENAME as String = Server.MapPath(" minutes.txt")

将objStreamReader变暗为StreamReader

objStreamReader = File.OpenText(FILENAME)


昏暗contents as String = objStreamReader.ReadToEnd()

lblRawOutput.Text = contents


objStreamReader.Close()

end sub

< / script>

< b>会议纪要< / b>< br />

< asp:label runat =" server" ID = QUOT; lblRawOutput" />
I''m trying to display a text file on a web page and the code below works
fine
and display the text on a webpage. However,if I use (as I need to) a
masterpage and then place the code in a webform that uses the masterpage
all
it does is display the words ''Meeting minutes'' which is the header for the
text right at the bottom of the code below. Is there something in a
masterpage that prevents this working at all?
Cheers
ArtySin

<%@ Import Namespace="System.IO" %>
<script language="vb" runat="server">
sub Page_Load(sender as Object, e as EventArgs)

Dim FILENAME as String = Server.MapPath("minutes.txt")

Dim objStreamReader as StreamReader
objStreamReader = File.OpenText(FILENAME)

Dim contents as String = objStreamReader.ReadToEnd()
lblRawOutput.Text = contents

objStreamReader.Close()
end sub
</script>

<b>Meeting Minutes</b><br />
<asp:label runat="server" id="lblRawOutput" />






ArtySin写道:
ArtySin wrote:

那个斯科特没有运气。我试过了:

(~daily.txt")

(〜/ minutes.txt")

(〜/ pathname / minutes.txt" ;)


但这些都不起作用.....任何其他想法/
No luck with that Scott. I tried:
(~minutes.txt")
(~/minutes.txt")
(~/pathname/minutes.txt")

but none of these works at all ..... any other ideas/



如果你看一下浏览器中的源代码,文本已放在

中以某种方式使其不可见,例如卡在评论中<! - 或类似的?


Andrew

If you look at the source in the browser, has the text been put in there in
some way to make it invisible, e.g. stuck in a comment <!-- or similar?

Andrew


这篇关于StreamReader和文本文件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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