Create Text File

Results 1 to 3 of 3

Thread: Create Text File

  1. #1
    Join Date
    Dec 1969

    Default Create Text File

    Anyone know a good tutorial on how to create a text file using FSO??

  2. #2
    RDM Guest

    Default Will this suffice?

    &nbsp;<BR> Dim oFS<BR> Dim oFSFile<BR> <BR> Const ForWriting =2<BR> Set oFS = CreateObject("Scripting.FileSystemObject")<BR> Set oFSFile = oFS.OpenTextFile("c: empmyfile.txt",ForWriting,True)<BR> oFSFile.Write("this is my string")<BR> oFSFile.Close<BR> Set oFSFile = Nothing<BR> Set oFS = Nothing

  3. #3
    Join Date
    Dec 1969

    Default RE: Will this suffice?

    It would - except I would like to write a recordset to a text file. <BR><BR>Here is my Code<BR><BR>If request.querystring("go") = "now" Then<BR>&#039; Get the file name<BR>strFileName = request.form("filename")<BR>strFilePath = "C:DataemeddataJunkColin"<BR><BR>sSql = "SELECT * FROM tblTmpMailing"<BR><BR>Set dbConn=Server.CreateObject("ADODB.Connection")<BR> dbConn.Open "Provider=SQLOLEDB;" & _<BR> "Initial Catalog=AdCampaign;" & _<BR> "Data Source=localhost;" & _<BR> "User Id=wwwdb;" & _<BR> "Password=5%^j*oo@;"<BR>Set RS=dbConn.Execute(sSql)<BR><BR>&#039; Declare variables for the File System Object and the File to be accessed.<BR>Dim objFSO<BR><BR>&#039; Create an instance of the the File System Object and assign it to objFSO.<BR>Set objFSO = CreateObject("Scripting.FileSystemObject")<BR><BR> objFSO.CreateTextFile(strFilePath & strFileName)<BR>Const fsoForWriting = 2<BR><BR>&#039; Open the file<BR>Set objTextFile = objFSO.OpenTextFile("" & strFilePath & strFileName & "", fsoForWriting, True)<BR><BR>Do While Not RS.EOF<BR>objTextStream.WriteLine Response.write("" & RS("TMFName") & "," RS("TMLName") & "," & RS("TMEmailAddress")"") & vbcrlf<BR>RS.MoveNext<BR><BR>Wend<BR>objTextStream .Close<BR>Set objTextStream = Nothing<BR><BR>objTextFile.Close<BR>Set objFSO = Nothing<BR><BR>dbConn.close<BR>set dbConn = nothing<BR><BR>Response.write("Text File has been created - " & strFilePath & strFileName)<BR>Response.end<BR>End If<BR><BR>Let me know what I am doing wrong. It really isnt giving an error, it just isnt working.

Posting Permissions

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