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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

write to text file on server

Status
Not open for further replies.

abhayrao

Technical User
Nov 5, 2002
16
0
0
IN
could you tell me how to write user input to a text file which is on the server which i can view. I really need it.
-abhayrao
 
Try this:

<%@ Language=VBScript %>
<%
Dim LogFile, LogMsg
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim FSO

LogFile = &quot;\\server123456\LogFiles\SQL_LogFile.txt&quot;
LogMsg = Request.Form(&quot;text1&quot;) & &quot; | &quot; & Request.Form(&quot;text2&quot;) & &quot; | &quot; & Request.Form(&quot;text3&quot;)

Sub Log_Report(strFile, strMsg)
' This sub add the lines to the file named above
Set FSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
If NOT FSO.FileExists(strFile) then
Set objRpt = FSO.OpenTextFile(strFile, ForWriting, TRUE)
Else
Set objRpt = FSO.OpenTextFile(strFile, ForAppending, TRUE)
End If
objRpt.write StrMsg
objRpt.writeblanklines(1)
objRpt.close
Set objRpt = Nothing
End Sub

%>
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
</HEAD>
<BODY>
<%If Request.QueryString(&quot;action&quot;)=&quot;senddata&quot; Then
Call Log_Report(logFile, logMsg)%>
<h2>Data sent!</h2>
<%Else%>
<form name=&quot;senddata&quot; action=&quot;logfile.asp?action=senddata&quot; method=&quot;post&quot;>
<table border=&quot;1&quot; width=&quot;50&quot;>
<tr><th>Name</th><th>Address</th><th>Phone Number</th></tr>
<tr><td><input name=&quot;text1&quot;></td>
<td><input name=&quot;text2&quot;></td>
<td><input name=&quot;text3&quot;></td></tr>
</table>
<p><input type=&quot;submit&quot; value=&quot;Submit&quot; name=&quot;submit&quot;></p>
</form>
<%End If%>
</BODY>
</HTML>

Also, if you open and make a search for CreateObject(&quot;Scripting.FileSystemObject&quot;), you will probably get a lot of sites with explanations how this object works. You can also use DYNU object to work with the files from ASP pages.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top