Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 8th, 2007, 12:59 PM
Authorized User
 
Join Date: Jan 2005
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?

  #2 (permalink)  
Old September 8th, 2007, 01:03 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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
  #3 (permalink)  
Old September 8th, 2007, 01:55 PM
Authorized User
 
Join Date: Jan 2005
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

How is this done from a HTML file?

  #4 (permalink)  
Old September 8th, 2007, 02:36 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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
  #5 (permalink)  
Old September 8th, 2007, 06:45 PM
Authorized User
 
Join Date: Jan 2005
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The HTML file is the file containing the actual HTML I want to display.

  #6 (permalink)  
Old September 9th, 2007, 02:55 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

In that case, take a look at the System.IO.File class. It has convenient methods to read in a text file:

http://msdn2.microsoft.com/en-us/lib...e_methods.aspx

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
  #7 (permalink)  
Old September 9th, 2007, 07:05 AM
Authorized User
 
Join Date: Jan 2005
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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


  #8 (permalink)  
Old September 9th, 2007, 07:11 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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
  #9 (permalink)  
Old September 9th, 2007, 05:47 PM
Authorized User
 
Join Date: Jan 2005
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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")

  #10 (permalink)  
Old September 9th, 2007, 07:11 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML email problem in asp.net sanjivbshinde ASP.NET 2.0 Professional 5 May 29th, 2008 06:49 AM
HTML Button in Asp.Net vallabh53 .NET Framework 1.x 0 October 17th, 2007 01:01 AM
viewing xml inside an html file Tomi XML 1 August 2nd, 2006 05:06 AM



All times are GMT -4. The time now is 02:14 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.