Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2006

Tip: Looking for answers? Try searching our database.

How read HTML contents into a string?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
VB Programmer - 20 Feb 2006 02:15 GMT
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?
Lau Lei Cheong - 20 Feb 2006 02:21 GMT
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" <dont@emailme.com> ¼¶¼g©ó¶l¥ó·s»D:uXum5NcNGHA.3728@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?
VB Programmer - 20 Feb 2006 02:37 GMT
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

> If the HTML file is located on your server, just read it as ordinary text
> file and perform string.Replace() on the placeholders
[quoted text clipped - 4 lines]
>>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?
Lau Lei Cheong - 20 Feb 2006 04:56 GMT
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" <dont@emailme.com> ¼¶¼g©ó¶l¥ó·s»D:eo$$GacNGHA.740@TK2MSFTNGP12.phx.gbl...
>I wrote a function which reads it ok.  (See below)
>
[quoted text clipped - 34 lines]
>>>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?
Russell - 20 Feb 2006 14:15 GMT
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.

> I wrote a function which reads it ok.  (See below)
>
[quoted text clipped - 35 lines]
> >>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?
VB Programmer - 20 Feb 2006 18:32 GMT
Bingo!  Thanks alot Russell (and everyone else!!)

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)
>
[quoted text clipped - 38 lines]
> >>contents
> >>into a string (for the body of an email.)  How can I do this?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.