FileWrite Statement:
Writes to a text file.
Description:
The FileWrite statement allows writing to a file. The FileWrite statement has three required arguments: pathname, texttowrite, and overwrite. The first argument is pathname. Pathname must be the complete path to an already existing file. The second argument texttowrite is a string containing the text to add to the file. To add more than one line of text, use vbCrLf. The third argument is a boolean representing overwriting. If the overwrite argument is set to True, the complete contents of the file is replaced with texttowrite. If it is set to False, the texttowrite string is appended to the file's contents.
Syntax:
FileWrite pathname, texttowrite, overwrite
Example:
<%
'--- Overwrites the contents of File.txt with 2 lines of text. FileWrite server.mappath("/New Folder/File.txt"), "line 1 txt" & vbCrLf & "line 2 txt" & vbCrLf, True
'--- Appends 2 lines of text to the the contents of File.txt. WriteFile server.mappath("/New Folder/File.txt"), "line 1 txt" & vbCrLf & "line 2 txt" & vbCrLf, False
%>
ASP Source Code:
<%
Private Sub FileWrite(byVal pathname, byVal strToWrite, byVal boolOverWrite) dim objFSO, objFile, boolErr, strErrDesc, lngWriteMethod On Error Resume Next Set objFSO = Server.CreateObject("Scripting.FileSystemObject") if boolOverWrite then lngWriteMethod = 2 else lngWriteMethod = 8 end if Set objFile = objFSO.OpenTextFile(pathname, lngWriteMethod, False) objFile.Write strToWrite If Err Then boolErr = True strErrDesc = Err.Description End If objFile.Close Set objFile = Nothing Set objFSO = Nothing On Error GoTo 0 if boolErr then Err.Raise 5107, "FileWrite Statement", strErrDesc End Sub
%>
|