Forum Moderators: open

Message Too Old, No Replies

File Includes

set to load on date?

         

mossimo

11:24 am on May 15, 2003 (gmt 0)

10+ Year Member



Any one know of some simple ASP code that will call a file include such as:
<!--#include file="whatever"--> based on the date or a set number of days. The idea is to load next week’s news article automatically. The file includes could be named:
week_1, week_2, ect.

Thank's
mossimo

aspdaddy

1:53 pm on May 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



AFAIK you cannot do dynamic includes in ASP, the best you can do a is a big select...case

But, maybe you could dynamically create the asp file based on the date?

mossimo

2:25 pm on May 15, 2003 (gmt 0)

10+ Year Member



Maybe I should ask my host but on my current site i using includes, nothing more than <!--#include file="whatever"--> it works fine.

This may work because of COM components installed on my server?

I am also using includes and a little VBS to display random ads, If I could only turn random into scheduled?

davemarks

10:24 pm on May 15, 2003 (gmt 0)

10+ Year Member



Include files are included before the script is processed, therefore you cannot dynamically change the file name, you could have

SELECT CASE bla
Case 1:
<!--#include file="whatever"-->
Case 2:

etc etc etc

But the best way is probably try and database the content that changes, then provide an admin interface for making the changes - will make life a whole lot easier ;)

macrost

11:48 pm on May 15, 2003 (gmt 0)

10+ Year Member



davemarks,
Have you implemented that type of code before? I tried to use an include when I was using a COM, however, I found out that the include needs to be outside of a script block or within an html page. If you do this, I believe that the script will fail.

<%
Select "filename"
case "1"
%>
<!-- #include file="whatever" -->
<%
case "2"
%>
<!-- #include file="another" -->
<%
End Select
%>

I'm not sure but I think even that will fail. Please someone agree or rebutt my statement.
Mac

davemarks

12:13 pm on May 16, 2003 (gmt 0)

10+ Year Member



Yeah sorry the include needs to be outside the delimiters. How you posted would work fine, but like i say all files will be included and make one large file, which will then be processed by the asp engine....

aspdaddy

12:47 pm on May 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It will work, but you need to know all the filenmames in advance.

Another idea i just had is to use the filesystem to open a dynamically named file based on the date. I havent tried it but I dont see why it cant work:

Set objText = objFile.OpenTextFile("whatever_" & getWeekNo(Now()) & ".txt",fsoForReading)

Response.write objText.ReadAll

davemarks

4:36 pm on May 16, 2003 (gmt 0)

10+ Year Member



Yeah that true, aslong as the file you're importing is pure html, you could read it in using the file system object and then simply print it out in the asp...

Gizmare

10:41 pm on May 16, 2003 (gmt 0)

10+ Year Member



I would add that using the Filesystem Object will degrade performance in a highly utilized scenario.

macrost

3:06 am on May 17, 2003 (gmt 0)

10+ Year Member



That is true, FSO will degrade any high performance code that is already made. FSO is notoriously slow... let me think on another way to accomplish this, and I should have an answer by Monday, if someone hasn't already answered it. :-)
Mac

mossimo

12:17 pm on May 17, 2003 (gmt 0)

10+ Year Member



Thanks for the options,

With all the free or low cost scripts out there I’m thinking it might just make more sense to go with a pre-built content management system.

But where’s the fun in that.

mossimo

6:40 pm on May 19, 2003 (gmt 0)

10+ Year Member



Yes it can been done easly with XSSI (eXtended Server-Side Includes)
only avalable on Apache web-servers (wich i don't have, o darn)

<!--#config timefmt="%Y%m%d" -->

<!--#if expr="$DATE_LOCAL < 19980917" -->

<P>This will be shown before my birthday in 1998
<!--#endif -->
<!--#if expr="$DATE_LOCAL >= 19980917" -->

<P>This will be shown during and after my birthday in 1998
<!--#endif -->

Xoc

5:17 am on May 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Include file processing is done before the processing of ASP. So you can't use ASP to change include files. You can, however, use the FileSystemObject to load the content.

davemarks

10:59 pm on May 20, 2003 (gmt 0)

10+ Year Member



Wohoo!

<%
somePage = "home.asp"
Server.Execute(somePage)
%>

Stumbled across this while looking up some other info on MSDN
Although I've seen/read about it before, it never really struck home until now what it did.

This basically works the same as an include :D

macrost

12:21 am on May 21, 2003 (gmt 0)

10+ Year Member



davemarks,
Yes, I forgot about that... I have some mass mailing software that requires the Server.Execute line to add the sign up box. I haven't implemented it yet, but it seems to be stable. Not sure if it will work in this situation tho.
Mac

davemarks

2:33 pm on May 21, 2003 (gmt 0)

10+ Year Member



I just tried to apply it to a page where i was previously using response.redirect, the page didn't initialise anything that could have caused problems with the second page, but it failed and didn't give a very helpful message.

It worked fine on another couple of pages i tried though, but the calling page only had html in it...

Def worth a try though.... i must have a play again and see if i can get it too do what i want ;)

aspdaddy

7:08 pm on May 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This was added into IIS v5, it lets you call asp pages as functions, also Server.Transfer which is similar to Response.Redirect

davegerard

12:53 am on May 23, 2003 (gmt 0)

10+ Year Member



I tried Davemarks' method including page02.asp into page01.asp and it returned the following error in IIS.

Microsoft VBScript runtime error '800a01b6'

Object doesn't support this property or method: 'Server.Execute'

page01.asp, line 4

were you using IIS on an NT box?

Dave

davegerard

12:55 am on May 23, 2003 (gmt 0)

10+ Year Member



IIS 5? Sorry I didn't realize this board had two pages so I didn't see aspdaddy's reply.