Results 1 to 3 of 3

Thread: View HTML Source in a Program

  1. #1
    Join Date
    Apr 2009

    View HTML Source in a Program

    I'm attempting to make a very basic HTML editor in VB for an assignment. and one of the requirements is that I be able to enter a URL and have it retrieve the HTML of whatever page I sent it to. however I'm not sure how I would accomplish this. any help would be appreciated

  2. #2
    Join Date
    Dec 2008

    Re: View HTML Source in a Program

    Dim webResponse3 As System.Net.HttpWebResponse = Nothing
    Dim webRequest3 As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("")
    webResponse3 = DirectCast(webRequest3.GetResponse(), System.Net.HttpWebResponse)
    Dim srResp As System.IO.StreamReader
    srResp = New System.IO.StreamReader(webResponse3.GetResponseStream())
    dim SOMESTRING as string
    SOMESTRING = srResp.ReadToEnd
    Catch ex As Exception

    End Try

  3. #3
    Join Date
    Feb 2008

    Re: View HTML Source in a Program

    This example will show you how use a string in VB to create PHP code.In order to do this, you need a string to store your PHP page and a function that I will list at the bottom of the page for you to put in a module. This code is written in VB.NET

    Public Sub CreatePage(ByVal HTMLTitle As String, ByVal HTMLText As String, ByVal HTMLFileName As String)
    Dim strFile As String
    ' ----------------------
    ' -- Prepare String --
    ' ----------------------
    strFile = ""
    ' --------------------
    ' -- Write Starter --
    ' --------------------
    strFile = "<html>" & vbNewLine
    strFile = strFile & "<head>" & vbNewLine
    strFile = strFile & "<title>" & HTMLTitle & "</title>" & vbNewLine
    strFile = strFile & "</head><body>" & vbNewLine
    strFile = strFile & HTMLText & vbNewLine
    strFile = strFile & "</body></html>"
    SaveTextToFile(strFile, "C:\" & HTMLFileName & ".html")
    End Sub
    Now we're done with the sub for creating the page, this is the only other snippet of code you will need, this needs to go into a
    module of your program.

    Public Function SaveTextToFile(ByVal strData As String, _ ByVal FullPath As String, _ Optional ByVal ErrInfo As String = "") As Boolean

    Dim Contents As String
    Dim Saved As Boolean = False
    Dim objReader As IO.StreamWriter
    objReader = New IO.StreamWriter(FullPath)
    Saved = True
    Catch Ex As Exception
    ErrInfo = Ex.Message
    End Try
    Return Saved
    End Function
    As you can see, the code has a wide range of uses, such as taking old INI databases from your applications and being able to turn them into a useable webpage. Just take the strFile and add onto it with any HTML code or even PHP, all you'd have to do is change the ending on the save function inside the CreatePage sub.

Similar Threads

  1. Replies: 1
    Last Post: 08-06-2012, 12:42 PM
  2. Unable to view the source code in Firefox
    By Siketan in forum Technology & Internet
    Replies: 5
    Last Post: 14-04-2011, 12:42 AM
  3. View HTML files in Kindle
    By GurdeepS in forum Portable Devices
    Replies: 4
    Last Post: 22-03-2010, 07:52 PM
  4. Java program to retrieve html source
    By Aaliya Seth in forum Software Development
    Replies: 5
    Last Post: 12-01-2010, 10:59 AM
  5. How to View HTML Source Code in Word 2007
    By Rutajit in forum Windows Software
    Replies: 3
    Last Post: 08-08-2009, 12:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts