Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2007
    Thanked 0 Times in 0 Posts

    Problem with add a file detail to database

    I write a asp code to find files in the server directory as user type in the html page.when it find out ,it show file list that match value's user typing with "open file" button.If user click the button,it will add data about the opening file to database and show a hyperlink of that file
    I have a problem at this point.I want to add the data of opeing only one file that user click but asp think that I want to open every files in the server directory.It will add the data of opening files in every to database.

    this my code and my page.Please edit my code.I have to sent it on tuesday.I don't know to solve it anymore.Help!!!
    Dim strPath   
    Dim objFSO   
    Dim objFolder 
    Dim strQuery
    strPath = "C:\upload\"
    strQuery = Request.QueryString("filesearch")
    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFSO.GetFolder(strPath)
    Contents of <strong><%= strPath %></strong> that match your query:
    <table border="5" bordercolor="green" cellspacing="0" cellpadding="2">
        <tr bgcolor="#006600">
            <td><font color="#FFFFFF"><strong>File&nbsp;Name:</strong></font></td>
            <td width="50%"></td>
    For Each x In objFolder.Files
        If InStr(1, x.Name, strQuery, vbTextCompare) <> 0 Then
            <tr bgcolor="#CCFFCC">
                <td align="left" ><%= x.Name %></td>
                <td><form action="openfilesv.asp" method="post"><input type="submit" name=openf value="Open it"></form>
    			<% if request.form("openf")<>"" then 
    				    Set Objdb = Server.CreateObject("ADODB.Connection") 
    					Objdb.Open "provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=c:\inetpub\wwwroot\mywebproject\fileinfo.mdb;"  
    					Set RS = Server.CreateObject("ADODB.Recordset") 
    					SQL = "SELECT * FROM [FileInfo]" 
    					RS.Open SQL,Objdb,1,3 
    					RS.Fields("Access Date")= Now
    					RS.Fields("File Name")=x.Name & "be opened"
    					Set RS=Nothing
    					Set Objdb=Nothing%>
    					<a href="<%= strPath & x.Name %>"><%= x.Name %></a>
    				<% end if%></td>
        End If
    Set objItem = Nothing
    Set objFolder = Nothing
    Set objFSO = Nothing
    set opf=nothing
    set objfile=nothing
    set objFSO=nothing
    I give user type file name.In this picture,I type hello

    It shows result

    I click only the button that is right of "hello.txt".It shows this

    this picture is my database after I click to open only "hello.txt"

    Last edited by davincith; 09-23-2007 at 03:18 PM.

  • #2
    Regular Coder
    Join Date
    Mar 2007
    Thanked 19 Times in 19 Posts
    I see your issue. You are using a SELECT * FROM [FileInfo] to get the records, but you need to use a WHERE statement to alter the name.

    Also, you need to make sure that your form is not posting to every file.

    Right now, you are saying in your code:

    If my form is not empty, for every file that I have change the features.
    You want it to say:

    If my form is not empty, check my files for the one that I want, change its features, and leave the rest alone.
    Here's what you need to do in order to fix this:

    1) Set a hidden field with either your File Name OR your File's ID number.

    2) ON Form Post, compare the above hidden field to the files in your database.

    3) When you find a match, alter the Access Date and the File Name. Basically, your SQL statement should say SELECT * FROM [FileInfo] WHERE <hidden_field> = <hidden_field_value>

    Couple quick notes:

    1) NEVER, ever, unless absolutely necessary, use SELECT *. Always type in the fields you want to see into your SELECT statement.

    2) Even in Access, spaces in Field Names is a big no-no. Change your field names to Access_Date and File_Name.

    3) NOW is a function. It should be NOW(). Just because it works does not mean that you should be using it incorrectly.

    To say my fate is not tied to your fate is like saying, 'Your end of the boat is sinking.' -- Hugh Downs
    Please, if you found my post helpful, pay it forward. Go and help someone else today.


    Posting Permissions

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