View Single Post
Old December 8th, 2005, 04:14 PM
BrianWren BrianWren is offline
Friend of Wrox
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts

Absolutely! (In the following, you might have to make some adjustments for trailing back slashes, etc.)
I tried to make all the changes I made boldface, but read carefully...
I substituted .WriteLine for .Write in locations where it was clear that the contents of what was being written would not have any linefeeds of carriage returns. So I left ("Heading") and ("Contents") as .Write.
    Dim cnctn, rs             ' » Both Connection and Recordset are words
    Dim sSQL, sConnString     '   naming specific items in the data access
    Dim sThisPage             '   object models;  it’s good idea to stay
    Dim TempPath              '   away from such names...
    Dim fso
    Dim Mnth
    Dim f
    Dim s   ' Temp string
    Dim x   ' Throw away variable to catch the created folder
            ' when using sFSO.CreateFolder() As Folder

    ' Declare SQL stmnt that will query the db
    sSQL = "SELECT * FROM DeHavillandNews"

    ' Define the connection string, specify db driver
    ' and the location of db
    sConnString  = "PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _ 
                   "Data Source=" & Server.MapPath("casinonewsxml.mdb") 

    ' Create an ADO connection & recordset
    Set cnctn = Server.CreateObject("ADODB.Connection")
    Set rs    = Server.CreateObject("ADODB.Recordset")

    ' Open the connection to the db
    cnctn.Open sConnString

    ' Open the recordset, execute the SQL stmnt
    rs.Open sSQL, cnctn

    ' Create an instance of the FileSystemObject
    Set fso = Server.CreateObject("Scripting.FileSystemObject")

    ' Loop through all the records in the db
    Do While Not rs.EOF

        ' Get the month from the recordset
        Mnth = Mid(rs("DtFld"), 4, 2)   ' (I’m assuming a field name...)
        ' If DtFld is a true date field, use VB’s date manipulation
        ' Mnth = CStr(Month(rs("DtFld")))

        ' Check for the existence of the folder.
        ' Create it if non-existent.
        s = Server.MapPath("htmlpages/a.txt"      ' Generate file path & name
        s = Left(s, Len(s) - 5)                   ' Strip the file name
        If Not fso.FolderExists(s) Then           ' Look for it
            Set x = fso.CreateFolder("s" & Mnth)  ' Create it
            Set x = Nothing                       ' Release the reference
        End If

        ' Map a path to a unique file name based on the id in the db
        sThisPage = Server.MapPath("htmlpages/" & Mnth & "/" & rs("ItemID") & ".asp")

        ' Check whether the file exists already;
        ' delete it if so.
     '  TempPath = sThisPage    ' Doesn’t appear that TempPage differs from sThisPage . . .
        If fso.FileExists(sThisPage) Then
        End If

        ' Create a new file & fill it with content
        Set f = fso.CreateTextFile(sThisPage, True)

        f.WriteLine "<p class='newshead'>"
        f.Write     rs("Heading") & vbCrLf
        f.WriteLine "</p><p class='newstext'>"
        f.Write     rs("Contents") & vbCrLf
        f.WriteLine "</p>"
        Set f = Nothing