Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



View HTML Source in a VB.net Program

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 09-04-2009
Member
 
Join Date: Apr 2009
Posts: 1
View HTML Source in a VB.net 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

Reply With Quote
  #2  
Old 09-04-2009
Member
 
Join Date: Dec 2008
Posts: 322
Re: View HTML Source in a VB.net Program

Dim webResponse3 As System.Net.HttpWebResponse = Nothing
Dim webRequest3 As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://www.yahoo.com")
Try
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
Reply With Quote
  #3  
Old 09-04-2009
Member
 
Join Date: Feb 2008
Posts: 1,843
Re: View HTML Source in a VB.net 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)
Code:
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

Code:
Dim Contents As String
Dim Saved As Boolean = False
Dim objReader As IO.StreamWriter
Try

objReader = New IO.StreamWriter(FullPath)
objReader.Write(strData)
objReader.Close()
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "View HTML Source in a VB.net Program"
Thread Thread Starter Forum Replies Last Post
Using PHP to extract Source IP from email header input via HTML form TimB Software Development 1 08-06-2012 12:42 PM
Unable to view the source code in Firefox Siketan Technology & Internet 5 14-04-2011 12:42 AM
View HTML files in Kindle GurdeepS Portable Devices 4 22-03-2010 07:52 PM
Java program to retrieve html source Aaliya Seth Software Development 5 12-01-2010 10:59 AM
How to View HTML Source Code in Word 2007 Rutajit Windows Software 3 08-08-2009 12:50 PM


All times are GMT +5.5. The time now is 05:14 AM.