473,396 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How read HTML contents into a string?

I have an HTML file that I want to read on the fly and insert the contents
into a string (for the body of an email.) How can I do this?
Feb 20 '06 #1
5 5914
If the HTML file is located on your server, just read it as ordinary text
file and perform string.Replace() on the placeholders
you reserved.

"VB Programmer" <do**@emailme.com> ¼¶¼g©ó¶l¥ó·s»D:uX**************@tk2msftngp13.phx.g bl...
I have an HTML file that I want to read on the fly and insert the contents
into a string (for the body of an email.) How can I do this?

Feb 20 '06 #2
I wrote a function which reads it ok. (See below)

The only probelm is that the HTML shows up in the email message with the raw
code, even though I set IsBodyHtml to true. Any ideas?

Here's the code to read the html...

Private Function ReadHtmlPage(ByVal url As String) As String

Dim file As String = Server.MapPath(url)

Dim sr As System.IO.StreamReader

Dim fi As New System.IO.FileInfo(file)

Dim strContents As String = ""

If System.IO.File.Exists(file) Then

sr = System.IO.File.OpenText(file)

strContents += Server.HtmlEncode(sr.ReadToEnd())

sr.Close()

End If

Return strContents

End Function
"Lau Lei Cheong" <le****@yehoo.com.hk> wrote in message
news:Oy*************@TK2MSFTNGP14.phx.gbl...
If the HTML file is located on your server, just read it as ordinary text
file and perform string.Replace() on the placeholders
you reserved.

"VB Programmer" <do**@emailme.com>
¼¶¼g©ó¶l¥ó·s»D:uX**************@tk2msftngp13.phx.g bl...
I have an HTML file that I want to read on the fly and insert the contents
into a string (for the body of an email.) How can I do this?


Feb 20 '06 #3
If you can see the raw code, then the "read" part should be OK.

I believe you should post the "send" code in order for us to find out what's
wrong.

"VB Programmer" <do**@emailme.com> ¼¶¼g©ó¶l¥ó·s»D:eo*************@TK2MSFTNGP12.phx.gb l...
I wrote a function which reads it ok. (See below)

The only probelm is that the HTML shows up in the email message with the
raw code, even though I set IsBodyHtml to true. Any ideas?

Here's the code to read the html...

Private Function ReadHtmlPage(ByVal url As String) As String

Dim file As String = Server.MapPath(url)

Dim sr As System.IO.StreamReader

Dim fi As New System.IO.FileInfo(file)

Dim strContents As String = ""

If System.IO.File.Exists(file) Then

sr = System.IO.File.OpenText(file)

strContents += Server.HtmlEncode(sr.ReadToEnd())

sr.Close()

End If

Return strContents

End Function
"Lau Lei Cheong" <le****@yehoo.com.hk> wrote in message
news:Oy*************@TK2MSFTNGP14.phx.gbl...
If the HTML file is located on your server, just read it as ordinary text
file and perform string.Replace() on the placeholders
you reserved.

"VB Programmer" <do**@emailme.com> ¼¶¼g©ó¶l¥ó·s»D:uX**************@tk2msftngp13.phx.g bl...
I have an HTML file that I want to read on the fly and insert the
contents into a string (for the body of an email.) How can I do this?



Feb 20 '06 #4
Try changing

strContents += Server.HtmlEncode(sr.ReadToEnd())

to

strContents += sr.ReadToEnd()

You are actually destroying your tags at that point because the HTML
encoding converts '<' to "&lt;", '>' to "&gt;", etc, which then appear
as literal characters in your email.
VB Programmer wrote:
I wrote a function which reads it ok. (See below)

The only probelm is that the HTML shows up in the email message with the raw
code, even though I set IsBodyHtml to true. Any ideas?

Here's the code to read the html...

Private Function ReadHtmlPage(ByVal url As String) As String

Dim file As String = Server.MapPath(url)

Dim sr As System.IO.StreamReader

Dim fi As New System.IO.FileInfo(file)

Dim strContents As String = ""

If System.IO.File.Exists(file) Then

sr = System.IO.File.OpenText(file)

strContents += Server.HtmlEncode(sr.ReadToEnd())

sr.Close()

End If

Return strContents

End Function
"Lau Lei Cheong" <le****@yehoo.com.hk> wrote in message
news:Oy*************@TK2MSFTNGP14.phx.gbl...
If the HTML file is located on your server, just read it as ordinary text
file and perform string.Replace() on the placeholders
you reserved.

"VB Programmer" <do**@emailme.com>
¼¶¼g©ó¶l¥ó·s»D:uX**************@tk2msftngp13.phx.g bl...
I have an HTML file that I want to read on the fly and insert the contents
into a string (for the body of an email.) How can I do this?



Feb 20 '06 #5
Bingo! Thanks alot Russell (and everyone else!!)

"Russell" <ru*****@goisc.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Try changing

strContents += Server.HtmlEncode(sr.ReadToEnd())

to

strContents += sr.ReadToEnd()

You are actually destroying your tags at that point because the HTML
encoding converts '<' to "&lt;", '>' to "&gt;", etc, which then appear
as literal characters in your email.
VB Programmer wrote:
I wrote a function which reads it ok. (See below)

The only probelm is that the HTML shows up in the email message with the
raw
code, even though I set IsBodyHtml to true. Any ideas?

Here's the code to read the html...

Private Function ReadHtmlPage(ByVal url As String) As String

Dim file As String = Server.MapPath(url)

Dim sr As System.IO.StreamReader

Dim fi As New System.IO.FileInfo(file)

Dim strContents As String = ""

If System.IO.File.Exists(file) Then

sr = System.IO.File.OpenText(file)

strContents += Server.HtmlEncode(sr.ReadToEnd())

sr.Close()

End If

Return strContents

End Function
"Lau Lei Cheong" <le****@yehoo.com.hk> wrote in message
news:Oy*************@TK2MSFTNGP14.phx.gbl...
If the HTML file is located on your server, just read it as ordinary
text
file and perform string.Replace() on the placeholders
you reserved.

"VB Programmer" <do**@emailme.com>
¼¶¼g©ó¶l¥ó·s»D:uX**************@tk2msftngp13.phx.g bl...
I have an HTML file that I want to read on the fly and insert the
contents
into a string (for the body of an email.) How can I do this?


Feb 20 '06 #6

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

Similar topics

5
by: Markus Ernst | last post by:
Hello I have a regex problem, spent about 7 hours on this now, but I don't find the answer in the manual and googling, though I think this must have been discussed before. I try to simply...
2
by: LaBird | last post by:
Dear all, I'd like to know if there is any function or program call in C++ (without memory protection support by OS), that can determine whether an object is being read or written? e.g., a =...
5
by: ashton | last post by:
Hello, I have a file (mytest.fle) it is just a text file with a different extension. I would like to be able to open this file through my C++ application and read it in as a string. For...
4
by: ESPN Lover | last post by:
Below is two snippets of code from MSDN showing how to read a file. Is one way preferred over the other and why? Thanks. using System; using System.IO; class Test { public static void...
10
by: Tibby | last post by:
I need to read/write not only text files, but binary as well. It seems like on binary files, it doesn't right the last 10% of the file. -- Thanks --- Outgoing mail is certified Virus...
4
by: Kuldeep | last post by:
Hi All, I am trying to read the contents of a page through its URL. My code snippet is as follows: public void mtdGetPageDataHWR() { HttpWebRequest objRequ =...
9
by: =?Utf-8?B?TWlrZQ==?= | last post by:
Hi. Is it programatically possible in VB.NET to read the contents of web.config's <customErrorselement? I looked at using ConfigurationSettings.AppSettings, but that doesn't work. I need to...
1
by: Shashank | last post by:
Hi all, I am a new member of this community. I am making a http request to a html file placed on a Apache server. On this page there is an embeded perl statement which requires reading ...
4
by: Mr Gray | last post by:
Hi Guys, My requirement is to scan an FTP directory for the presence of 4 files and if a specific file exists I can begin to GET those files, read the contents and save the contents into an SQL...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.