Reference html file from an aspx file

G

Guest

Hi,

I am trying to reference an html page from an aspx file. The intention is
that the html file will contain the content for my web site and the aspx will
contain the navigation, logo etc. Then I am hoping I can maintain the html
files separately via Frontpage.

I have tried a server include i.e.

<!-- #Include File="c:\somedirectory\somefilename.htm" -->

This works fine except that referenced images are not displayed. Also, I
can't programatically include the file, or at least I can't see how to do
that.

So the question is: How can I reference an html page from an aspx file so
that the referenced images will be displayed.

The only option I can see would be to use the full url for each image (i.e.
http://www.someurl.com/someimagename.jpg etc) but I can't do that as the
exact url is not known at document creation time.

Regards,

Steve Bugden.
 
K

Kevin Spencer

A server-side include is a pre-processor directive. This means something
different when you're talking about procedural vs. object-oriented
programming. ASP is procedural. ASP.Net is object-oriented. The biggest
difference with regards to server-side includes is the behavior of the app.
In a procedural app, program flow runs from top to bottom in a more or less
"straight line" with some side trips to functions and sub-routines. In an
object-oriented app, program flow hops around from one class to another, and
events drive much of the processing, which involves multi-threading. A
pre-processor directive means that prior to compilation, the pre-processor
directives are carried out. This enables, for example, some code in an
include file to be included in the app code, prior to compilation (so that
it runs after compilation). In a procedural app, this has the desired effect
of inserting the code you include at that point in the procedural execution
of the app. In an object-oriented app, as process jumps around, when you're
talking about user interface elements, you have little or no knowledge of
where in the execution that code will be processed. This may (and often
does) result in the interface code you insert being processed in an
unexpected or undesirable point, with undesirable results.

Bottom line is, if you want to use ASP.Net, learn object-oriented,
event-driven programming concepts, and apply them to your app. Don't use
pre-processor directives for inserting interface code into your pages.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
T

Tod Birdsall

Hi Steve,

Are you only using .aspx pages to display these .htm pages? One
solution may be:
1. Put a place holder like #PATH# in front of the image path in the
..htm file (i.e. #PATH#/myimage.gif).
2. Put a Literal control on your referencing .aspx page.
2. Use a StreamReader to read the contents of the .html file in your
code behind file.
3. Replace all instances of the #PATH# with Request.ApplicationPath
4. Set the Literal control's .Text property to the newly formated .html
page contents.

Example code: (NOT TESTED)

System.IO.StreamReader StreamReader1 = new
System.IO.StreamReader(Server.MapPath("c:\somedirectory\somefilename.htm"));
string myString = StreamReader1.ReadToEnd();
myString = myString.Replace("#PATH#", Request.ApplicationPath)
LiteralControl1.Text = myString;
StreamReader1.Close();

There is probably an easier way to do this, but this is what readily
comes to mind.

Tod Birdsall, MCP
http://tod1d.blogspot.com
 
G

Guest

Hi Tod,

Thanks for your answer.

I did try this approach already, the problem is that certain characters are
ignored. For example when reading the word "Zürich" the 'u' with umlaut is
ignored and the word is displayed as 'Zrich'.

Is there something else I can do to get it to interpret correctly?

Best Regards,

Steve

Steve.
 
G

Guest

Hello Kevin,

Thankyou for your reply but I'm not sure how it helps.

Firstly, I'm not using a server side include, it doesn't do what I need, if
it did I would use it. I used it to save explaining in too many words what I
want to try to achieve.

Secondly, I'm not sure how object oriented programming will help as what I
need is a technique for reading and interpreting the html file. Tod's
solution is more what I was looking for (please see my separate reply) but I
was hoping there might be an easier technique perhaps using a url where the
images of the page would be picked up automatically.

Best Regards,

Steve.
 
G

Guest

Hi Gopal,

THanks for the idea, but unfortunately I'm not using frames.

Best Regards,

Steve.
 
G

Guest

OK I can answer my own question:

I changed the encoding i.e.

Dim stexenc As System.Text.Encoding
stexenc = encoding.getencoding(1252)
TextFile = New StreamReader(strFIlename, stexenc )

All characters are correctly read.

Many thanks once again for the help

Regards,

Steve.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top