Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2004
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    adding files to db

    I a trying to get this to read a folder then write the files to a list in a access db.
    Also one of the things I need it to do is clear the db before it adds the files something like.

    Code:
    If Len(Request.Form("Add"))  Then
    ClearDatabase()
    sql = "DELETE FROM filelist"
    conn.Execute sql
    Response.Write "Database emptied"
    But not sure how t add it where it will clear the db then add the files maybe I will try adding it to beinning of the function. Where am I mesing up.
    Code:
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <%
    set conn=Server.CreateObject("ADODB.Connection")
    conn.Provider="Microsoft.Jet.OLEDB.4.0"
    conn.Open Server.MapPath("/database/downloads.mdb")
    Function insertFilesToDatabase()
    dim fs,fo,x
    set fs=Server.CreateObject("Scripting.FileSystemObject")
    set fo=fs.GetFolder(Server.MapPath("/downloads"))
    for each x in fo.files
    'Print the name of all files in the test folder
    sql = "INSERT INTO filelist (filename, filesize, filepath, filedescription) VALUES ("
    sql = sql & "'" & x.Name & "'," & x.Size & ",'" & x.Path & "','" & x.Type & "'"
    sql = sql & ")"
    Response.Write sql & "<br>"
    conn.Execute sql
    next
    set fo=nothing
    set fs=nothing
    Response.Write "Files Added!<br><hr><br>"
    insertFilesToDatabase = true
    End Function
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>downloads</title>
    </head>
    <body>
    <form name="form1" method="post" action="">
    <input name="Add" type="submit" id="Add" value="Add Files">
    
    </form>
    <%
    conn.close
    %>
    </body>
    </html>

  • #2
    Senior Coder BarrMan's Avatar
    Join Date
    Feb 2005
    Location
    Israel.
    Posts
    1,644
    Thanks
    69
    Thanked 83 Times in 82 Posts
    To delete the database table use:
    Code:
    sql = "DROP TABLE filelist"
    And your adding files code looks fine.
    Just call the function clearDatabase() inside the insertFilesToDatabase function.

  • #3
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The full script is here
    http://forums.aspfree.com/asp-develo...Database%28%29

    Code:
    If Len(Request.Form("Add")) > 0 Then
    Call ClearDatabase()
        If insertFilesToDatabase = true Then
            Call outputFileList
        End If
    End If


  •  

    Posting Permissions

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