473,800 Members | 2,726 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5932
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.c om> ¼¶¼g©ó¶l¥ó·s»D: uX************* *@tk2msftngp13. phx.gbl...
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(By Val url As String) As String

Dim file As String = Server.MapPath( url)

Dim sr As System.IO.Strea mReader

Dim fi As New System.IO.FileI nfo(file)

Dim strContents As String = ""

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

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

strContents += Server.HtmlEnco de(sr.ReadToEnd ())

sr.Close()

End If

Return strContents

End Function
"Lau Lei Cheong" <le****@yehoo.c om.hk> wrote in message
news:Oy******** *****@TK2MSFTNG P14.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.c om>
¼¶¼g©ó¶l¥ó·s»D: uX************* *@tk2msftngp13. phx.gbl...
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.c om> ¼¶¼g©ó¶l¥ó·s»D: eo************* @TK2MSFTNGP12.p hx.gbl...
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(By Val url As String) As String

Dim file As String = Server.MapPath( url)

Dim sr As System.IO.Strea mReader

Dim fi As New System.IO.FileI nfo(file)

Dim strContents As String = ""

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

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

strContents += Server.HtmlEnco de(sr.ReadToEnd ())

sr.Close()

End If

Return strContents

End Function
"Lau Lei Cheong" <le****@yehoo.c om.hk> wrote in message
news:Oy******** *****@TK2MSFTNG P14.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.c om> ¼¶¼g©ó¶l¥ó·s»D: uX************* *@tk2msftngp13. phx.gbl...
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.HtmlEnco de(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(By Val url As String) As String

Dim file As String = Server.MapPath( url)

Dim sr As System.IO.Strea mReader

Dim fi As New System.IO.FileI nfo(file)

Dim strContents As String = ""

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

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

strContents += Server.HtmlEnco de(sr.ReadToEnd ())

sr.Close()

End If

Return strContents

End Function
"Lau Lei Cheong" <le****@yehoo.c om.hk> wrote in message
news:Oy******** *****@TK2MSFTNG P14.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.c om>
¼¶¼g©ó¶l¥ó·s»D: uX************* *@tk2msftngp13. phx.gbl...
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.goo glegroups.com.. .
Try changing

strContents += Server.HtmlEnco de(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(By Val url As String) As String

Dim file As String = Server.MapPath( url)

Dim sr As System.IO.Strea mReader

Dim fi As New System.IO.FileI nfo(file)

Dim strContents As String = ""

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

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

strContents += Server.HtmlEnco de(sr.ReadToEnd ())

sr.Close()

End If

Return strContents

End Function
"Lau Lei Cheong" <le****@yehoo.c om.hk> wrote in message
news:Oy******** *****@TK2MSFTNG P14.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.c om>
¼¶¼g©ó¶l¥ó·s»D: uX************* *@tk2msftngp13. phx.gbl...
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
5190
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 extract the title and meta tags of a valid HTML page as an array: function extract_html($filename)
2
2125
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 = b + c; // a is being written while b and c are being read a++; // a is being read and written
5
1423
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 example, I would right click on this file, select open with, then navigate to my EXE to open this file.
4
2754
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 Main()
10
2546
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 Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.538 / Virus Database: 333 - Release Date: 11/10/2003
4
4196
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 = (HttpWebRequest)WebRequest.Create("http://www.microsoft.com"); HttpWebResponse objResp = (HttpWebResponse)objRequ.GetResponse();
9
4275
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 read the value of redirect from the error statusCode 404. My web.config looks like this: <customErrors mode="RemoteOnly" defaultRedirect="Error.aspx"> <error statusCode="404" redirect="Error404.aspx" /> </customErrors>
1
3142
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 environment variables from the server. When I am typing the url of the html page in my browser, I am able to read the Environment variables from the server and getting the desired results. But, when I am making Http request through my window application,...
4
11107
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 2005 DB. The files are of a fixed length format which map to certain elements of data that my database will exploit. If i can learn to read 1 file and put the contents into the DB then I can do the other 3 on my own. So far I can connect to the...
0
9691
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
10279
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
9092
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...
1
7582
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6815
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5473
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...
0
5607
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3765
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2948
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.