View Full Version : Read and Write Files

09-23-2005, 09:50 AM
Hi all,

one question ... Exist in Javascript the option to Write and read files ?

something like:

if user enter here then write 1 on example.txt


if user enter here then read example.txt




09-23-2005, 10:09 AM
You can use the FileSystemObject to read/write files in Internet Explorer and there is a Mozilla alternative, but there will be nasty security warnings popping up at best, and this process will be totally blocked at worst by the user's browser.

If the application is to be run localy on a windows machine, you can use an .hta file or somesuch. If possible - try to do this server-side.

09-24-2005, 03:24 PM
hi all,

hmmm first of all thanks for the feedback (y)))))

but i have a problem ... im new in javascript programmation so i need to ask you one more thing ... could you make a sample of a FileSystemObject for i learn how that works please? Thanks .... Don't need many options something for i test and see how that works ... and also if you want your SiteLogo for i put on my afiliates sites (I like ask for help but i like also put a "linkback" for who help me)


PS: or as alternative if you know how we create a .hta when we are running with a IIS server and Win 2003 as OS.

09-24-2005, 05:34 PM
Use ASP/VBScript:

Writing a file:
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("c:\testfile.txt", True)
MyFile.WriteLine("This is a test.")
Reading a file:
Const ForReading = 1
Dim fso, f, strContents
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("c:\testfile.txt", ForReading)
strContents = f.ReadAll
FileSystemObject Reference (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/jsmthopentextfile.asp)

But you'd be better off using a database to store data in.

Hope this helps.


09-24-2005, 08:35 PM
thanks, i think so ...

bye (b)