Current location: Hot Scripts Forums » Programming Languages » ASP » Using a form to replace data in a text file


Using a form to replace data in a text file

Reply
  #1 (permalink)  
Old 12-21-08, 10:42 PM
dnb198 dnb198 is offline
New Member
 
Join Date: Dec 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Using a form to replace data in a text file

Hi,

I'm redesigning the homepage of a website which is supposed to have a box on the front page that displays the title of the latest entry on the website's wordpress hosted blog. I would like the five people who write on the blog to be able to easily manually update what is written in the box whenever they want through a form on a password protected page.

The website is written in ASP, however, I do not have access to the SQL database on the server. Therefore, the text that appears in the box on the homepage is stored in a txt file named blogtitle.txt.

I would like to have a simple form where you could type in a sentence (the title of the latest blog post) and the form would go into blogtitle.txt and replace what had been written previously with the new title. It's important that the form replaces the previous contents of blogtitle.txt rather than simply add to it.

In other words, each time you type a sentence into the form, it does two things:

1. Erases the previous contents of blogtitle.txt
2. Writes the new form data to blogtitle.txt

Is there a very simple way to do this using an ASP script? Keep in mind, I know very little about ASP.

Thanks
Reply With Quote
  #2 (permalink)  
Old 12-22-08, 06:26 AM
Yeroon's Avatar
Yeroon Yeroon is offline
Code Master
 
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
If the txt file is in the rootfolder, then try something like this:

asp Code:
  1. <%
  2.  
  3. if(request.Form("SubmitButton")) then
  4.  
  5.   strPathInfo = ("mytextfile.txt") //root path to text file
  6.   strPhysicalPath = Server.MapPath(strPathInfo) //full file path to text file
  7.  
  8.   Set objFSO = createObject("Scripting.fileSystemObject") //new filesystemobject
  9.   Set objtext = objFSO.createtextfile(fName, true) //create new text file with the same name
  10.  
  11.   thenewline = Request.form("thenewline")
  12.   objtext.Write(thenewline) //write contents to new file
  13.   objtext.Close //done
  14. end if
  15. %>
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ajax checking and onsubmit issue follower JavaScript 4 10-12-08 03:45 PM
div css theighost CSS 11 09-14-08 02:30 AM
Submit button data written to a .txt file ziul Everything Java 0 08-08-07 03:41 PM
Submit text in a form to txt file Dooms_day PHP 2 02-16-06 05:54 AM


All times are GMT -5. The time now is 04:05 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.