Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New Coder
    Join Date
    Jan 2005
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Executing Code from text file

    I'm reading from a textfile but I want to know how to execute ASP code stored in a text file. Is it possible?

    <%
    DIM Page, FSO, TSO,RL, Temp1, Temp2, Temp3
    Dim Cont as String, URL1
    Page = REQUEST("Page")
    URL1 = Server.MapPath("Development/" & Page)
    FSO = Server.CreateObject("Scripting.FileSystemObject")
    if NOT FSO.Fileexists(URL1) then
    URL1 = Server.MapPath("Articles/Article1/Article1") & ".txt"
    Page = "Article1"
    end if
    TSO = FSO.OpenTextFile(URL1)
    RL = TSO.ReadLine
    If instr(RL, "Menu Title: ") then
    temp1 = Replace(RL,"Menu Title: ", "")
    else temp1 = "Page Links:"
    end if
    %>
    <div class="layout_leftcontainer">
    <div id="vnav1">
    <div class="vnav1_top"></div><ul>
    <li class="vnav1_title"><%Response.write(Temp1)%></li>

    <li><a href="/Articles/" target="_self">Go Back</a></li>
    <%
    Do While Not TSO.AtEndOfStream
    RL = TSO.ReadLine
    If RL = "Start Link" then
    RL = ""
    temp1= Replace(TSO.ReadLine, "LinkName: ", "")
    temp2= Replace(TSO.ReadLine, "LinkURL: ", "")
    temp3= Replace(TSO.ReadLine, "LinkTarget: ", "")%>
    <li><a href="<%=temp2%>" target="<%=temp3%>"><%=temp1%></a></li>
    <%TSO.ReadLine
    end if
    Cont = Cont & RL
    Loop

    Cont = Replace(Cont, "[Path]","Articles/" & Page & "/")
    TSO.close
    %>

  • #2
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,062
    Thanks
    4
    Thanked 8 Times in 8 Posts

    yes as an include file inside an .asp page

    adovbs.inc and cdovbs.inc are two such examples

    The thing is if your code is in a text file then it can be read by a user. Security wise it is not a good idea.

  • #3
    New Coder
    Join Date
    Jan 2005
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I hate to include files and if you include the file in a text file, it will not work because the include files are processed before actual runtime.

    There must be a function that lets you execute code from a text file?

  • #4
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ever heard of functions or sub routines? Why would you want to include code in a text file, bad idea. Look into functions.

  • #5
    Regular Coder
    Join Date
    Aug 2002
    Location
    Texas
    Posts
    287
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Create your file as an *.asp file, NOT as a text file. Include the asp file.

    Within that file you can have functions you can call from the including page....

    fv

  • #6
    New Coder
    Join Date
    Jan 2005
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If I creeate it as a ASP file instead of text file and include THAT file, theres going to be a 1000 includes LOL.

    I just want to execute a piece of asp code from text file. Is it possible or not? thats what i want to know

  • #7
    Regular Coder
    Join Date
    Aug 2002
    Location
    Texas
    Posts
    287
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nope - not possible.


    Why do you say that there will be 1000 includes? Makes no sense to me...

    fv

  • #8
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,062
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Yes you can, HOWEVER it will run at the very beginning of the page, no matter where you place the include file on the page. Why not just save the code snippet as .asp? This will also save the code from prying eyes.

    Oh and if you don't believe me do something simple like this

    <%
    Dim TodaysDate
    TodaysDate = Date()
    Response.write. TodaysDate
    %>

    Save that as test.txt

    then on an asp page add this code
    <!--#include file="test.txt"-->
    save the page on your server and run it . No matter where you place the include file on your page, the date will show at the very top of the page.

    change the name to test.asp and where ever you place the include file, that is where the date will be displayed.

  • #9
    New Coder
    Join Date
    Jan 2005
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That does not work.

    Heres what Iam trying to do.

    I have a bunch of articles stored in text files about computers.
    Most of the articles are pure text but some of the articles need to connect to a database and do some stuff etc.

    And all the articles are being read from a ASP page that reads text files etc.

  • #10
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,062
    Thanks
    4
    Thanked 8 Times in 8 Posts

    what didnt work?

    did you include the delimiters? <% %> if the are not part of the text file, then no it will not work. As for reading info from a text file your best bet is to use the file system object to read it .

  • #11
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    i dont know if server.execute("...") works with .txt files, that can be used instead of <!--#include file="..." --> but with a dynamic filename if you want it (asp3+ only but you probably are using asp3)

    i once wrote a system that used fso to run txt files, as i wanted users to be able to write txt files that had some functionality such as variables and if statements without knowing asp, .. this just used a lot of complicated code to pretty much run a fake language i invented with very few commands for simplicity (like i had If_admin_... that would only write "..." if the reader realises its an admin logged on, etc)

  • #12
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Quote Originally Posted by ghell
    i dont know if server.execute("...") works with .txt files, that can be used instead of <!--#include file="..." --> but with a dynamic filename if you want it (asp3+ only but you probably are using asp3)
    That's what I'd suggest you try as well.
    OracleGuy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •