Reference html file from an aspx file

Discussion in 'ASP .Net' started by =?Utf-8?B?U3RldmUgQnVnZGVu?=, Feb 3, 2005.

  1. 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.
    =?Utf-8?B?U3RldmUgQnVnZGVu?=, Feb 3, 2005
    #1
    1. Advertising

  2. 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.

    "Steve Bugden" <> wrote in message
    news:...
    > 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.
    Kevin Spencer, Feb 3, 2005
    #2
    1. Advertising

  3. =?Utf-8?B?U3RldmUgQnVnZGVu?=

    Tod Birdsall Guest

    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
    Tod Birdsall, Feb 3, 2005
    #3
  4. You will have to ensure that the html page and the images are in the www
    directories. Then you can use frames for the html page.
    Hope this helps.

    --
    Gopal Rangaswamy
    Microsoft Certified Solutions Developer
    FMS, Inc.
    <http://www.fmsinc.com/consulting>
    <http://www.fmsinc.com/dotnet/SourceBook/>

    "Steve Bugden" <> wrote in message
    news:...
    > 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.
    Gopal \(FMS, Inc.\), Feb 3, 2005
    #4
  5. 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.

    "Tod Birdsall" wrote:

    > 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
    >
    >
    =?Utf-8?B?U3RldmUgQnVnZGVu?=, Feb 3, 2005
    #5
  6. 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.


    "Kevin Spencer" wrote:

    > 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.
    >
    > "Steve Bugden" <> wrote in message
    > news:...
    > > 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.

    >
    >
    >
    =?Utf-8?B?U3RldmUgQnVnZGVu?=, Feb 3, 2005
    #6
  7. Hi Gopal,

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

    Best Regards,

    Steve.

    "Gopal (FMS, Inc.)" wrote:

    > You will have to ensure that the html page and the images are in the www
    > directories. Then you can use frames for the html page.
    > Hope this helps.
    >
    > --
    > Gopal Rangaswamy
    > Microsoft Certified Solutions Developer
    > FMS, Inc.
    > <http://www.fmsinc.com/consulting>
    > <http://www.fmsinc.com/dotnet/SourceBook/>
    >
    > "Steve Bugden" <> wrote in message
    > news:...
    > > 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.

    >
    >
    >
    =?Utf-8?B?U3RldmUgQnVnZGVu?=, Feb 3, 2005
    #7
  8. 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.

    "Steve Bugden" wrote:

    > 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.
    >
    > "Tod Birdsall" wrote:
    >
    > > 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
    > >
    > >
    =?Utf-8?B?U3RldmUgQnVnZGVu?=, Feb 3, 2005
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. x
    Replies:
    1
    Views:
    1,965
    John Timney \(Microsoft MVP\)
    Nov 30, 2003
  2. Alain Sienaert

    Reference Delphi aspx page in VB.aspx

    Alain Sienaert, Jul 21, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    515
    Eliyahu Goldin
    Jul 22, 2004
  3. Paolo Pignatelli
    Replies:
    6
    Views:
    2,184
    Paolo Pignatelli
    Feb 21, 2005
  4. John M
    Replies:
    1
    Views:
    1,132
    Kumar Reddi
    May 29, 2005
  5. juan_mauricio_lopez

    Problem getting a reference to the HTML code generated by an .aspx

    juan_mauricio_lopez, Aug 1, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    106
    juan_mauricio_lopez
    Aug 1, 2006
Loading...

Share This Page