Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Asp To write a txt file

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Im new to this and I'm trying to write an asp page to create and write to a text file using the filesystem object. so I wrote three sort of similar function and none work
I constantly get errors: either Activex cant create object or if I add in the server.createobject it tells me that object required 'server'
If anyone has any ideas please let me know.

<%@ Language=VBScript %>
<html>
<body bgcolor=&quot;red&quot; background =&quot;flagback.jpg&quot; BGPROPERTIES=&quot;fixed&quot;>

<center>
<HR>
<Script Language=&quot;VBscript&quot;>
function Write_in_File()

Myfile = &quot;pleasework.txt&quot;
Set Fs = server.Createobject(&quot;Scripting.FileSystemObject&quot;)
msgbox MyFile
Set File_Name = Fs.createTextFile(Myfile,2,True)
File_Name.Write TEXT1.value
File_Name.Close
Set File_Name = Nothing
Set Fs = Nothing
End function

Sub cmdSubmit_onclick()
call write_in_file
Call StringToFile(TEXT1.value,&quot;pleasework.txt&quot;)
call Session_OnStart
Text1.value = &quot;&quot;
End sub

Function StringToFile(StringToWrite, PathAndFilename)

on error resume next
const ForReading = 1'Open a file for reading only.
const ForWriting = 2' Open a file for writing only.
const ForAppending = 8 ' Open a file and write to the end of the file.
dim stf_fso, stf_File
Set stf_fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
If FileExist(PathAndFilename)then

Set stf_File = stf_fso_OpenTextFile(PathAndFilename, ForWriting, True)
msgbox PathAndFilename
Else
Set stf_File = stf_fso.CreateTextFile(PathAndFilename, True)
msgbox &quot;created file&quot;
End if
stf_File.Write strFileData
Set stf_File = nothing
Set stf_fso = nothing

End function

Function FileToString(PathAndFilename)

on error resume next
const ForReading = 1'Open a file for reading only.
const ForWriting = 2' Open a file for writing only.
const ForAppending = 8 ' Open a file and write to the end of the file.
dim stf_fso, stf_File
Set stf_fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
If FileExist(PathAndFilename) then
Set stf_File = stf_fso_OpenTextFile(PathAndFilename, ForWriting, True)
Else
Set stf_File = stf_fso.CreateTextFile(PathAndFilename, True)
End if
stf_File.Write strFileData
Set stf_File = nothing
Set stf_fso = nothing

End function

Function Session_OnStart
hits = hits + 1

Set fs = CreateObject(&quot;Scripting.FileSystemObject&quot;)
set hitfile = fs.CreateTextFile(&quot;hits.txt&quot;,True,false)
hitfile.WriteLine(Hits)
hitfile.Close


end Function
</script>

</center><TEXTAREA id=TEXT1 name=TEXTAREA1 style=&quot;HEIGHT: 104px; WIDTH: 462px&quot;>
 
Ok I added runat=&quot;server&quot; and now it runs but the button does not work now how do i fix that ?
 
Try <%%> instead of SCRIPT tag plus RUNAT attribute..

They have some difference in the order of execution... Thank you...
RR

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top