Using the FileSystemObject to Create an ASP Code Generator

Contributed by
Rating: 5 stars5 stars5 stars5 stars5 stars / 5
July 01, 2000
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement


-By Elaya Manickam Narayanan.

We all must have used the "Scripting.FileSystemObject" progid to create text
files. But only a few know that it can be used for writing all kinds of
files. For example, you can create html files using the filesystemobject.
And why not, you can even write ASP files using an asp file!
That's right! An ASP Code generator.

Here's the complete code of how this can be done:
Just copy and paste the following code into an asp file. Invoke your browser
and request the asp file. Eureka! The file generates its own asp file
(generatedasp.asp) and submits itself.
For any queries regarding this article mail me at elayamanickam@indya.com.
Happy programming!

<%

'Author Name : Elaya Manickam Narayanan
'Purpose : Generates as output an .asp file


'Create the ASP file
'Variables Declaration
Dim fso
Dim i
'Create Object for the ASP File
Set fso = Server.CreateObject("Scripting.FileSystemObject")
'Create the asp file
Set FileSys = fso.CreateTextFile(Server.mappath("generatedasp.asp"),true)
'Procedure to write the asp file
Call WriteASP()
'Close the file
FileSys.Close
'Release the reference
Set FileSys = Nothing

'Procedure for the body of the Generated asp file
Sub WriteASP()
    FileSys.WriteLine("<%")
FileSys.WriteLine("'******This file was generated by vbscript******")
FileSys.WriteLine("Response.write ""You logged in as:"" & Request(""login"")")
    FileSys.WriteLine("Response.Write ""<BR>""")
FileSys.WriteLine("Response.write ""Your password is:"" & Request(""password"")")
'In the following line '%' and '>' are intentionally seperated becos it 'generates an error if they are given together.
FileSys.WriteLine("%" & ">")
End Sub
%>
<html>
<head>
</head>
<body>
<form name = "form1" action = "Generatedasp.asp" method = "post">
    <table align = "center" border = "1">
    <tr>
        <td>
            Login
        </td>
        <td>
            <input type ="text" name ="login" maxlength = 12>
        </td>
    </tr>
    <tr>
        <td>
            Password
        </td>
        <td>
            <input type="password" name ="password" maxlength = 12>
        </td>
    </tr>
    <tr>
        <td>
        </td>
        <td>
        <input type ="Submit" value ="Submit">
        </td>
    </tr>
</table>
</form>
</body>
</html>

blog comments powered by Disqus
ASP CODE ARTICLES

- ASP Forms
- ASP: The Beginning
- Getting Remote Files With ASP Continued
- Inbox and Outbox Manipulation in ASP
- Relational DropDownList Using VB.NET
- Ad Tracking URL Hits
- Use ViewState to display one record per page...
- Send Email using ASP.NET formatted in HTML
- ASP File Explorer
- ASP/XML Interview questions by Srivatsan Sri...
- Pressing RETURN won't submit the form
- This shows how you get the TEXT of a combo r...
- Group Data by Adrian Forbes
- Multiple checkbox select sample
- Multiple checkbox select with all values sam...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials