Reading html body through ASP.Net

L

Luqman

How can I retrieve text from html file and write to textbox.

Best Regards,

Luqman
 
R

Ray Costanzo [MVP]

From another site? Or from the local file system? Here's a method for
reading from another site:

<form id="form1" runat="server">
<asp:TextBox id="txtURI" runat="server" Width="552px"></asp:TextBox>
<asp:Button id="cmdSubmit" runat="server" Text="Button"></asp:Button><br>
<asp:TextBox id="txtHTML" runat="server" TextMode="MultiLine" Width="616px"
Height="552px"></asp:TextBox></P>
</form>

Private Sub cmdSubmit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdSubmit.Click
Dim oRequest As System.Net.WebRequest
Dim oResponse As System.Net.WebResponse
Dim oReader As System.IO.StreamReader
Dim sResponse As String
Try
oRequest = System.Net.WebRequest.Create(txtURI.Text)
oResponse = oRequest.GetResponse
oReader = New System.IO.StreamReader(oResponse.GetResponseStream)
sResponse = oReader.ReadToEnd
Catch : sResponse = "Could not load page"
End Try
txtHTML.Text = sResponse
End Sub

Ray at work
 
M

Matt Berther

Hello Luqman,

using (StreamReader rdr = new StreamReader("c:\path\to\my\file.html"))
{
string text = rdr.ReadToEnd();

// at this point, you have the text of the HTML file in a variable.
// do with it what you need to...
}
 
L

Luqman

Hi Ray,

Your code is returning Html source, but I need html Output in textbox or
rich text box. Whatever you see in the browser when you click on html file,
I want to display same in rich text box, so that formatted text
(bold/underline) could be displayed, html file could be on local computer or
could be anywhere in web site.

I want to use the html formatted text in my mailmerge application.

The user create a message in any software like outlook express, microsoft
outlook or frontpage and save it in html format. Then using my application,
he can send mailmerge messages using message body from html file.

I hope you understand what I mean.

Best Regards,

Luqman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top