File Writer - Append | Language: | Server Sided ASP - JavaScript | Author: | Jon Lokken | Date: | 7-24-2008 | |
| Description: | View Example | Using the ASP file system object to write to a file. Make sure you set your permissions to read/write on the application server. |
<%@ LANGUAGE="JavaScript" %> <% Response.buffer=true %> <% var myReturn = "\u000A"; var myTab = "\u0009"; var myVerticalTab = "\u000B"; var myFormFeed = "\u000C"; var myCarriageReturn = "\u000D";
var objMyFSO = Server.CreateObject("Scripting.FileSystemObject"); var serverPath = Server.MapPath("/applications/programming/ASP/FileSystemObject/formData.txt"); var doesFileExist = objMyFSO.FileExists(serverPath);
if(doesFileExist){ // Read the file var pageTStream = objMyFSO.OpenTextFile(serverPath); var pageContents = ""; var lineNumber = 0; while(! pageTStream.AtEndOfStream){ var temp = "" + pageTStream.Readline() + "<br>"; pageContents = pageContents + temp + ""; lineNumber++; } Response.Write(pageContents); pageTStream.close();
// Write to the file <% pageTStream = objMyFSO.OpenTextFile(serverPath,8,true); pageTStream.WriteLine("\"New User"+lineNumber+"\",\"Lokken\",\"001\",\"1 Smith Rd\",\"Minneapolis\",\"MN\",\"55555\",\"612-333-3333\""); pageTStream.close(); } else{ Response.Write("The page has been moved or deleted from the server."); } %>
Disclaimer: | Feel free to use this code I have written. I take no responsibility for this code working, imply no warranty as to it's validity, and will not be held liable if you decide to try it. I am only trying to help out others so they don't have to struggle with the same problems as me... | |