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