How to write to a text file

Results 1 to 2 of 2

Thread: How to write to a text file

  1. #1
    Jolene Guest

    Default How to write to a text file

    Hi,<BR><BR>I need to write data on to text files and ftp to another server. I can successfully output the data to an asp page but it is not stored in the text file. Here is what I have done.<BR><BR>I have a text file called writeUserInfo.txt that contains the following:<BR>&#060;SCRIPT RUNAT=SERVER LANGUAGE="VBScript"&#062;<BR><BR>Function WriteToFile(strUserInfo)<BR> On Error Resume Next &#039prevent the code from halting on an error<BR> WriteToFile = False<BR> Set objFSO = CreateObject("Scripting.FileSystemObject")<BR> <BR> varOutputFile=Server.MapPath("/blstShop/SingTelUser/text") + "demo.txt"<BR><BR> Set objFile = objFSO.OpenTextFile("D:InetpubwwwrootlstshopSingT elUser extdemo.txt")<BR><BR> objFile.WriteLine(strUserInfo)<BR> objFile.Close<BR> WriteToFile=True<BR>End Function<BR><BR>&#060;/SCRIPT&#062;<BR>~~~<BR><BR>Then I include the file into my asp file that calls it.<BR>~~~<BR>while RS1.EOF = false<BR> shopper_id = RS1.Fields("shopper_Id").Value & vbNullString <BR> ic = RS1.Fields("ic").Value & vbCRLF<BR> subsplan = RS1.Fields("subsplan").Value & vbCRLF<BR>......<BR> str = vbNullString<BR> str = str & "IC: " & ic & "Subscription Plan: " & subsplan & vbCRLF<BR>......<BR> if WriteToFile(str) then<BR> Response.Write "&#060;p&#062;&#060;p&#062;ShopperID: " & shopper_id & "&#060;p&#062;"<BR> Response.Write "&#060;p&#062;&#060;p&#062;str: " & str & "&#060;p&#062;"<BR> else<BR> Response.Write "Error in " & Err.source<BR> Response.Write "<BR>" & Err.description & "&#060;p&#062;"<BR> end if<BR> rs1.MoveNext<BR>wend<BR>~~~<BR><BR>Q1. How can I write to text file?<BR><BR>Q2. I tried using objFile = objFSO.CreateTextFile instead of OpenTextFile but I get a "Permission Denied" error message. How can I resolve that? I have administrator access in the web server.<BR><BR>Thanks for your time.<BR><BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: How to write to a text file

    This line:<BR><BR>Set objFile = objFSO.OpenTextFile("D:InetpubwwwrootlstshopSingT elUser extdemo.txt")<BR><BR>opens the file for READ ONLY, so of course you can&#039t write to it.<BR><BR>If you can&#039t do CreateTextFile then, despite your claims, you have a permissions problem. Or the file already exists.<BR><BR>See the documentation for OpenTextFile and CreateTextFile for all the various options (such as, for the latter, overwriting an already existent file).<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts