Reading html body through ASP.Net

Discussion in 'ASP .Net' started by Luqman, Dec 6, 2004.

  1. Luqman

    Luqman Guest

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

    Best Regards,

    Luqman
    Luqman, Dec 6, 2004
    #1
    1. Advertising

  2. 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



    "Luqman" <> wrote in message
    news:...
    > How can I retrieve text from html file and write to textbox.
    >
    > Best Regards,
    >
    > Luqman
    >
    >
    Ray Costanzo [MVP], Dec 6, 2004
    #2
    1. Advertising

  3. Luqman

    Matt Berther Guest

    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...
    }

    --
    Matt Berther
    http://www.mattberther.com

    > How can I retrieve text from html file and write to textbox.
    >
    > Best Regards,
    >
    > Luqman
    >
    Matt Berther, Dec 6, 2004
    #3
  4. Luqman

    Luqman Guest

    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





    "Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
    message news:%...
    > 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
    >
    >
    >
    > "Luqman" <> wrote in message
    > news:...
    >> How can I retrieve text from html file and write to textbox.
    >>
    >> Best Regards,
    >>
    >> Luqman
    >>
    >>

    >
    >
    Luqman, Dec 8, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rick Spiewak
    Replies:
    5
    Views:
    796
    Lewis Wang [MSFT]
    Aug 1, 2003
  2. khawar
    Replies:
    1
    Views:
    474
  3. rgouge
    Replies:
    0
    Views:
    353
    rgouge
    Jul 29, 2005
  4. London Boy
    Replies:
    2
    Views:
    318
    Keith Bowes
    Jan 12, 2004
  5. Replies:
    5
    Views:
    200
    A. Sinan Unur
    Sep 8, 2005
Loading...

Share This Page