473,789 Members | 2,706 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

StreamReader and text file problem

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="Syst em.IO" %>
<script language="vb" runat="server">
sub Page_Load(sende r as Object, e as EventArgs)

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

Dim objStreamReader as StreamReader
objStreamReader = File.OpenText(F ILENAME)

Dim contents as String = objStreamReader .ReadToEnd()
lblRawOutput.Te xt = contents

objStreamReader .Close()
end sub
</script>

<b>Meeting Minutes</b><br />
<asp:label runat="server" id="lblRawOutpu t" />
Jun 27 '08 #1
10 1344
The problem is the path is not resolved properly when master pages are used.
Try this:

Dim FILENAME as String = Server.MapPath( "~minutes.t xt")
"ArtySin" <Ar*****@discus sions.microsoft .comwrote in message
news:15******** *************** ***********@mic rosoft.com...
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="Syst em.IO" %>
<script language="vb" runat="server">
sub Page_Load(sende r as Object, e as EventArgs)

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

Dim objStreamReader as StreamReader
objStreamReader = File.OpenText(F ILENAME)

Dim contents as String = objStreamReader .ReadToEnd()
lblRawOutput.Te xt = contents

objStreamReader .Close()
end sub
</script>

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


Jun 27 '08 #2
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:
The problem is the path is not resolved properly when master pages are used.
Try this:

Dim FILENAME as String = Server.MapPath( "~minutes.t xt")
"ArtySin" <Ar*****@discus sions.microsoft .comwrote in message
news:15******** *************** ***********@mic rosoft.com...
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="Syst em.IO" %>
<script language="vb" runat="server">
sub Page_Load(sende r as Object, e as EventArgs)

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

Dim objStreamReader as StreamReader
objStreamReader = File.OpenText(F ILENAME)

Dim contents as String = objStreamReader .ReadToEnd()
lblRawOutput.Te xt = contents

objStreamReader .Close()
end sub
</script>

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


Jun 27 '08 #3
ArtySin wrote:
No luck with that Scott. I tried:
(~minutes.txt")
(~/minutes.txt")
(~/pathname/minutes.txt")

but none of these works at all ..... any other ideas/
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
Jun 27 '08 #4
This is server-side code. It would not be rendered to the client and
therefore you wouldn't be able to see it.

The problem is that the path to the file to be read is being altered due to
the master page.

"Andrew Morton" <ak*@in-press.co.uk.inv alidwrote in message
news:67******** *****@mid.indiv idual.net...
ArtySin wrote:
>No luck with that Scott. I tried:
(~minutes.txt" )
(~/minutes.txt")
(~/pathname/minutes.txt")

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

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

Jun 27 '08 #5
I've sorted it!
The first line should be:
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load

All now works fine
ArtySin

*************** *************** ***********

"Scott M." wrote:
This is server-side code. It would not be rendered to the client and
therefore you wouldn't be able to see it.

The problem is that the path to the file to be read is being altered due to
the master page.

"Andrew Morton" <ak*@in-press.co.uk.inv alidwrote in message
news:67******** *****@mid.indiv idual.net...
ArtySin wrote:
No luck with that Scott. I tried:
(~minutes.txt")
(~/minutes.txt")
(~/pathname/minutes.txt")

but none of these works at all ..... any other ideas/
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


Jun 27 '08 #6
Oops! I didn't even look at that line. Let me ask you something...did you
write that event handler yourself? You should NEVER have to write the stub
of an event handler if you are using Visual Studio. If you do write them
yourself, as you've seen, you can make mistakes with them.

-Scott

"ArtySin" <Ar*****@discus sions.microsoft .comwrote in message
news:9C******** *************** ***********@mic rosoft.com...
I've sorted it!
The first line should be:
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles
Me.Load

All now works fine
ArtySin

*************** *************** ***********

"Scott M." wrote:
>This is server-side code. It would not be rendered to the client and
therefore you wouldn't be able to see it.

The problem is that the path to the file to be read is being altered due
to
the master page.

"Andrew Morton" <ak*@in-press.co.uk.inv alidwrote in message
news:67******* ******@mid.indi vidual.net...
ArtySin wrote:
No luck with that Scott. I tried:
(~minutes.txt" )
(~/minutes.txt")
(~/pathname/minutes.txt")

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

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



Jun 27 '08 #7
No, I didn't write this myself, I got the code from 4guysfromrolla. com and
they missed it out too

"Scott M." wrote:
Oops! I didn't even look at that line. Let me ask you something...did you
write that event handler yourself? You should NEVER have to write the stub
of an event handler if you are using Visual Studio. If you do write them
yourself, as you've seen, you can make mistakes with them.

-Scott

"ArtySin" <Ar*****@discus sions.microsoft .comwrote in message
news:9C******** *************** ***********@mic rosoft.com...
I've sorted it!
The first line should be:
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles
Me.Load

All now works fine
ArtySin

*************** *************** ***********

"Scott M." wrote:
This is server-side code. It would not be rendered to the client and
therefore you wouldn't be able to see it.

The problem is that the path to the file to be read is being altered due
to
the master page.

"Andrew Morton" <ak*@in-press.co.uk.inv alidwrote in message
news:67******** *****@mid.indiv idual.net...
ArtySin wrote:
No luck with that Scott. I tried:
(~minutes.txt")
(~/minutes.txt")
(~/pathname/minutes.txt")

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

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



Jun 27 '08 #8
That's not quite what I mean. The fact is that you did put that line in
there (via copy/paste) and you should never do that with an event handler.
The 4guysfromrolla. com code is just fine, it's written to work in an
environment where AutoEventWireUp (page level directive) is set to True.

What I meant was that you (whether your "wrote" the code yourself or you
paste it in there) should NEVER be writing the first or last line of an
event handler procedure. You should always let Visual Studio do it for you.
In the case of a web page load event, all you need to do is double click on
the page designer surface and VS will take you to code view and create the
event handler stub ready for you to fill in.

By letting VS do this kind of work for you will eliminate many problems like
this one.

Good luck!
"ArtySin" <Ar*****@discus sions.microsoft .comwrote in message
news:14******** *************** ***********@mic rosoft.com...
No, I didn't write this myself, I got the code from 4guysfromrolla. com and
they missed it out too

"Scott M." wrote:
>Oops! I didn't even look at that line. Let me ask you something...did
you
write that event handler yourself? You should NEVER have to write the
stub
of an event handler if you are using Visual Studio. If you do write them
yourself, as you've seen, you can make mistakes with them.

-Scott

"ArtySin" <Ar*****@discus sions.microsoft .comwrote in message
news:9C******* *************** ************@mi crosoft.com...
I've sorted it!
The first line should be:
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles
Me.Load

All now works fine
ArtySin

*************** *************** ***********

"Scott M." wrote:

This is server-side code. It would not be rendered to the client and
therefore you wouldn't be able to see it.

The problem is that the path to the file to be read is being altered
due
to
the master page.

"Andrew Morton" <ak*@in-press.co.uk.inv alidwrote in message
news:67******* ******@mid.indi vidual.net...
ArtySin wrote:
No luck with that Scott. I tried:
(~minutes.txt" )
(~/minutes.txt")
(~/pathname/minutes.txt")

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

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




Jun 27 '08 #9
Andrew Morton wrote:
>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?
Scott M. wrote:
This is server-side code. It would not be rendered to the client and
therefore you wouldn't be able to see it.
Ummm... I was thinking that for some reason the data may have been inserted
into the rendered HTML but in a way that the browser didn't show it:

ArtySin wrote:
lblRawOutput.Te xt = contents
<snip>
<asp:label runat="server" id="lblRawOutpu t" />
Of course, the OP should check for File.Exists before trying to read it.

Andrew
Jun 27 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
4597
by: ShadowOfTheBeast | last post by:
Hi, I have got a major headache understanding streamReader and streamWriter relationship. I know how to use the streamreader and streamwriter independently. but how do you write out using the streamwriter, what you have read into a streamReader? and also can someone explain how they work in simple terms -- The Matrix Insurrection
3
3198
by: Mika M | last post by:
Hello! I'm reading text file line by line using the StreamReader like code below shows. Reading is working fine, but if readed line contains Scandinavian letters like äÄöÖ then those letters are simply cut off ! Why ??? For example my lastname Mähönen will be Mhnen. How should I change code to get all letters as is of the file? Dim strLine as String Dim sr As StreamReader = New StreamReader(strFilePath)
7
7773
by: Drew Berkemeyer | last post by:
Hello, I'm using the following code to read a text file in VB.NET. Dim sr As StreamReader = File.OpenText(strFilePath) Dim input As String = sr.ReadLine() While Not input Is Nothing strReturn += input + vbCrLf input = sr.Read
2
4193
by: James Wong | last post by:
Dear all, I'm using StreamReader to read a text file containing BIG-5 data and found that no matter which encoding method in StreamReader's construction parameter, the BIG-5 contents become garbage under ReadLine method. Does anybody have any idea on this issue? Thanks for your attention and kindly help! Regards,
11
31735
by: LucaJonny | last post by:
Hi, I've got a problem using StreamReader in VB.NET. I try to read a txt file that contains extended characters and theese are removed from the line that is being read. I've read a lot of articles about ANSI encoding like this http://support.microsoft.com/default.aspx?scid=kb;en-us;889835 but System.Text.Encoding.Default don't work!!
1
2230
by: JM | last post by:
Hi, I have been trying to read a file, using "StreamReader" to pass the info to an string that is: ....dim stream as new FileStream(file,...) dim sr as new StreamReader(stream) dim data as string = sr.ReadToEnd... My problem is that in the file (is a text file) there is some data like:
4
34191
by: George | last post by:
Hi, I am puzzled by the following and seeking some assistance to help me understand what happened. I have very limited encoding knowledge. Our SAP system writes out a text file which includes German characters. 1. When I use StreamReader(System.String filepath) without specifying an encoding method, the German characters such as Ä are lost when I do a ReadLine()
4
23051
by: moondaddy | last post by:
I need to edit the text in many files so I'm writing a small routine to do this. First I have a method that loops through all the files in a directory and passes the full file path to another method (ReadFile). I'm going to use this to edit the file paths in all of my WMP play lists. When I run this the string variable is not being changed using the replace method. Here's what I have: Private Sub ReadFile(ByVal path As String)
1
2876
by: Sladan | last post by:
Im trying to read a xml-file with a StreamReader. For the moment I'm using the following code. streamReader = new StreamReader(stream, System.Text.Encoding.Default); string feedData = streamReader.ReadToEnd(); I'm using System.Text.Encoding.Default so that I can get some swedish characters working. But I'm having problem when reading a xml-file that's encoded with UTF-8. In the beginning of the xml-files you have the encoding for the...
0
2362
by: rajana | last post by:
Dear All, We have Ansi file with german characters (Ä / Ø) , We are using Streamreader to read the contents of the file. But Readline() not able to read the German characters. We tried all possibilities of calling the streamreader, but nothing worked. Dim sr As StreamReader = New StreamReader(Filename, System.Text.Encoding.Default, True) Dim sr As StreamReader = New StreamReader(Filename, _System.Text.Encoding.ASCII, False, 512)
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10410
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9984
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5418
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4093
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.