txt to HTML

Is there a way to convert txt file to HTML in VB.net? Please provide links or code if have it. Thank you very much.
VBdotnet2005Asked:
Who is Participating?
 
blandyukConnect With a Mentor Commented:
If you simply want to have it formatted like the test, by in HTML, simple replace all vbCrLf with <br /> and Server.HTMLEncode the text, then write simple HTML tags and output to new file:

Imports System.IO

Dim text As String = File.ReadAllText(textFile)
Dim html As String

html = Server.HTMLEncode(text)
html = html.Replace(vbCrLf, "<br />" + vbCrLf)
html = "<html><body><p>" + html + "</p></body></html>"

File.WriteAllText("htmlFile", html)
0
 
CodeCruiserCommented:
Do you want to just add tags around the text?

I mean

My Sample String -> <html><body>My Sample String</body></html>

???
0
 
VBdotnet2005Author Commented:
I want to convert an actual txt (the whole file) into HTML file.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
VBdotnet2005Author Commented:
i don't see  Server.HTMLEncode
0
 
blandyukCommented:
Ah, you need to import the below and use HttpUtility.HtmlEncode:

Imports System.Web

html = HttpUtility.HtmlEncode(text)
0
 
VBdotnet2005Author Commented:
I did import, but I don't see HttpUtility.HtmlEncode

This is what I have. I am using VS 2008 pro
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Imports System.Data.OleDb
Imports Microsoft.Office.Interop
Imports System.Web
Imports System.Data.DataSet
Imports System.Data.DataTable
Imports System.Net.Mail
Imports System.Linq
Imports System.Text
Imports System.Text.RegularExpressions
Imports System.Xml
0
All Courses

From novice to tech pro — start learning today.