example: dates from May 1st to 31st total 31 days, so there are 31 notes need to be submitted. With a form to submit my notes and I want to save it to mynote.txt file not excel or SQL DB. today=date todaynote=request("todaynote") How to save them into mynote.txt page? Thanks
I'm assuming that you are talking about Classic ASP, here is some code to get you started. Dim objFso, objFile Set objFso = Server.CreateObject("Scripting.FileSystemObject") Set objFile=objFso.OpenTextFile(Server.MapPath("mynote.txt"),8,true) objFile.WriteLine(today) objFile.WriteLine(todaynote) objFile.Close Set objFile = Nothing Set objFso = Nothing Code (markup): The '8' in the following line is the mode: Set f=fspenTextFile(Server.MapPath("mynote.txt"),8,true) mode 1 is ForReading mode 2 is ForWriting and mode 8 is ForAppending The 'true' paramater is saying to create the file if it doesn't already exist. Other methods of the textstream object (objFile), depending on the mode are: objFile.Write(string) objFile.Read(length) objFile.ReadAll objFile.ReadLine
But I would recommend using a database, you could still output the comments as a textfile but you could easily refine the dates and delete and edit the comments much more easily
Thank you Camjohnson95, Could you guide me how to add the 2nd day's note to the mynote.txt without deleting the 1st day's note. Thank You / Best Regards,
Yes just use the same method, as it is opening the file in ForAppending mode (8) it will just add the new lines to the end of the file, ForWriting will overwrite the existing entries.
Thank you Camjohnson95, Excuse me, I was thinking how to edit the mynote.txt What if I use split any array to read mynote.txt (by mode 1 / ForReading ) then pick up the date which I want to edit and submit all new mynote string again (by mode 2 / ForWriting) Now my questions are: 1. What is the max size for a .txt file? 2. Will it slow down server by calling or saving the large size of mynote.txt? Thank You / Best Regards,
Yes it is possible to edit the file and insert or delete records by reading it all, making the changes, then rewriting it all back. There isn't really a max size, but if the file get's too large it will start to take longer to perform some tasks (especially editing and deleting records). This is a rough estimation but I reckon upto about 5000 records would be about the most that you would want to have if you are using this method, but i may be wrong. I would recommend that if you really want to use this method then use seperate textfiles for each date. E.g 01/05/09 would be stored in May2009.txt.