<% '******************************************************* '* ASP 101 Sample Code - http://www.asp101.com/ * '* * '* This code is made available as a service to our * '* visitors and is provided strictly for the * '* purpose of illustration. * '* * '* http://www.asp101.com/samples/license.asp * '* * '* Please direct all inquiries to webmaster@asp101.com * '******************************************************* %>

Current Web Log Contents:

Cool Stuff!!!


Add New Entry:

<% '****************************************************************************** '****************************************************************************** ' You'll want to manually format the include file to begin with. Each entry ' on it's own line. Each line terminated with a vbCrLf (carriage return/line ' feed) character. Please don't leave any extras at the end of the file except ' the one at the end of the last line (aka. the one that puts you on the first ' blank line at the end of the file). Which brings up an interesting point... ' an easy way to add more items to an include file is to add more blank lines ' to the end. As each new piece of new content is added, a blank line will ' be removed instead of the old content. So if a file currently has 5 entrys ' and you want ten, simply add 5 carriage returns to the end of the include ' file and save it. Then use the script as normal. You'll also want to check ' the permissions on this script and/or the include file. If this script is ' secured via NT, then the user might already have rights to modify the ' include file. Otherwise you'll need to modify the NTFS permissions to give ' the NTFS permissions on the include file to allow the anonymous internet ' user to write to it. '****************************************************************************** '****************************************************************************** ' Some functions to make my life easier! '****************************************************************************** Sub AddNewEntryToFile(strNewEntry, strVirtualFileName) Dim strFileContents ' Get existing file contents strFileContents = ReadTextFromFile(strVirtualFileName) ' Pull oldest entry off the bottom ' Assumes there is one vbCrLf at the end of each line and NO EXTRAS AT THE END OF THE FILE!!! strFileContents = Mid(strFileContents, 1, InStrRev(strFileContents, vbCrLf, (Len(strFileContents) - 2))) ' Add new entry to the top strFileContents = strNewEntry & vbCrLf & strFileContents ' Write full text including new entry back to file Call OverwriteFileWithText(strVirtualFileName, strFileContents) End Sub '****************************************************************************** Function ReadTextFromFile(strVirtualFileName) Dim strTemp Dim objFSO, objFile Set objFSO = Server.CreateObject("Scripting.FileSystemObject") ' Open the file as a text stream (1 = ForReading, True = Create) Set objFile = objFSO.OpenTextFile(Server.MapPath(strVirtualFileName), 1) ' Read contents of the file strTemp = objFile.ReadAll objFile.Close Set objFile = Nothing Set objFSO = Nothing ReadTextFromFile = strTemp End Function '****************************************************************************** Sub OverwriteFileWithText(strVirtualFileName, strFileContents) Dim objFSO, objFile Set objFSO = Server.CreateObject("Scripting.FileSystemObject") ' Overwrite existing file and get a text stream to new one Set objFile = objFSO.CreateTextFile(Server.MapPath(strVirtualFileName), True) ' Write updated content objFile.Write strFileContents objFile.Close Set objFile = Nothing Set objFSO = Nothing End Sub '****************************************************************************** '****************************************************************************** ' Runtime code... '****************************************************************************** Dim strHeadline Dim strURL ' Retrieve our form values strHeadline = Request.Form("headline") strURL = Request.Form("url") If Request.Form("submit") = "Add Entry" And strHeadline <> "" And strURL <> "" Then Dim strNewEntry ' Formatting is completely up to you... strNewEntry = "" _ & "" _ & Server.HTMLEncode(strHeadline) _ & "" Call AddNewEntryToFile(strNewEntry, "weblog.txt") %>

"<%= strHeadline %>" added to weblog.txt.

">View updated page.

<% Else %>
" method="post">
Headline:
URL:
<% End If %>