 |
| ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

September 8th, 2007, 12:59 PM
|
|
Authorized User
|
|
Join Date: Jan 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Viewing HTML in ASP.NET 2.0
Is there a way to view HTML from an ASP.NET 2.0 Web Application?
I have heard that you can use System.Web.UI.WebControls.Panel or System.Web.UI.WebControls.Literal control to do this.
I have tried both and neither gave me the results I expected.
I want to load a control from a HTML or RTF file and see the results in the web page exactly how it appears in the HTML or RTF file.
Is this possible? Or do I have to purchase a third-party control?
|
|

September 8th, 2007, 01:03 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
HTML yes, RTF no.
You can display HTML (provided it's code that is normally placed within the body tags) using a literal:
myLiteral.Text = "<h1>Hello World</h1>"
should display a heading in the page.
For RTF you need to look at third party components.
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
|
|

September 8th, 2007, 01:55 PM
|
|
Authorized User
|
|
Join Date: Jan 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
How is this done from a HTML file?
|
|

September 8th, 2007, 02:36 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
What do you mean with "from a HTML file"? Is the file containing the actual HTML you want to display, or are you trying to make this work *in* an HTML file?
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
|
|

September 8th, 2007, 06:45 PM
|
|
Authorized User
|
|
Join Date: Jan 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The HTML file is the file containing the actual HTML I want to display.
|
|

September 9th, 2007, 07:05 AM
|
|
Authorized User
|
|
Join Date: Jan 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Which one of the following methods are appropriate?
Public Function GetHtmlPageSource(ByVal vstrURL As String) As String
Dim url As New Uri(vstrURL)
Dim request As HttpWebRequest = HttpWebRequest.Create(url)
request.Method = WebRequestMethods.Http.Get
Dim response As HttpWebResponse = request.GetResponse
Dim reader As New StreamReader(response.GetResponseStream())
Dim tmp As String = reader.ReadToEnd
response.Close()
Return tmp
End Function
Public Function GetHtmlPageSource(ByVal vstrURL As String) As String
Dim st As System.IO.Stream = Nothing
Dim sr As System.IO.StreamReader = Nothing
Dim strReturn As String = ""
Try
Dim req As WebRequest = WebRequest.Create(vstrURL)
Dim resp As WebResponse = req.GetResponse()
st = resp.GetResponseStream()
sr = New System.IO.StreamReader(st)
strReturn = sr.ReadToEnd()
sr.Close() : st.Close()
Return strReturn
Catch ex As Exception
Return ""
End Try
End Function
|
|

September 9th, 2007, 07:11 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
It depends on where the HTML file comes from. If it's stored on disk, you can simply use ReadAllText of the File class I referred you to instead.
Maybe you should try to describe in a bit more detail what it is you're trying to accomplish. Makes it easier to provide a correct answer.
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
|
|

September 9th, 2007, 05:47 PM
|
|
Authorized User
|
|
Join Date: Jan 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The HTML is stored on the disk. I would like to call the method (GetHtmlPageSource). Then render the results of the method into a System.Web.UI.WebControls.Panel.
Something like
Panel1.? = GetHtmlPageSource("c:\temp\test.html")
|
|

September 9th, 2007, 07:11 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Have you looked at the System.IO.File class? This has all that you need.
http://msdn2.microsoft.com/en-us/lib...e_methods.aspx
You should be able to do this with one server control and one line of code. Use a literal control on the page as Imar suggested, then use the method on the file class that gets you the entire contents of the file:
<asp:literal runat="server" id="litHtml" />
litHtml.Text = System.IO.File.ReadAllText("filename")
You will need to resolve the file path to the physical path for the File class method to work properly. Use the MapPath method to translate the web application's virtual path to the physical path.
-Peter
|
|
 |