davincith
09-22-2007, 12:06 PM
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!!!
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
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)
%>
<p>
Contents of <strong><%= strPath %></strong> that match your query:
</p>
<table border="5" bordercolor="green" cellspacing="0" cellpadding="2">
<tr bgcolor="#006600">
<td><font color="#FFFFFF"><strong>File Name:</strong></font></td>
<td width="50%"></td>
</tr>
<%
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.Addnew
RS.Fields("Access Date")= Now
RS.Fields("File Name")=x.Name & "be opened"
RS.Update
RS.Close
Objdb.Close
Set RS=Nothing
Set Objdb=Nothing%>
<a href="<%= strPath & x.Name %>"><%= x.Name %></a>
<% end if%></td>
</tr></table>
<%
End If
Next
Set objItem = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
set opf=nothing
set objfile=nothing
set objFSO=nothing
%>
</table>
I give user type file name.In this picture,I type hello
http://img216.imageshack.us/img216/7996/88101899au7.th.jpg (http://img216.imageshack.us/my.php?image=88101899au7.jpg)
It shows result
http://img212.imageshack.us/img212/4521/83110706ef4.th.jpg (http://img212.imageshack.us/my.php?image=83110706ef4.jpg)
I click only the button that is right of "hello.txt".It shows this
http://img216.imageshack.us/img216/6099/32099936ya2.th.jpg (http://img216.imageshack.us/my.php?image=32099936ya2.jpg)
this picture is my database after I click to open only "hello.txt"
http://img166.imageshack.us/img166/6721/88354076hv8.th.jpg (http://img166.imageshack.us/my.php?image=88354076hv8.jpg)
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!!!
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
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)
%>
<p>
Contents of <strong><%= strPath %></strong> that match your query:
</p>
<table border="5" bordercolor="green" cellspacing="0" cellpadding="2">
<tr bgcolor="#006600">
<td><font color="#FFFFFF"><strong>File Name:</strong></font></td>
<td width="50%"></td>
</tr>
<%
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.Addnew
RS.Fields("Access Date")= Now
RS.Fields("File Name")=x.Name & "be opened"
RS.Update
RS.Close
Objdb.Close
Set RS=Nothing
Set Objdb=Nothing%>
<a href="<%= strPath & x.Name %>"><%= x.Name %></a>
<% end if%></td>
</tr></table>
<%
End If
Next
Set objItem = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
set opf=nothing
set objfile=nothing
set objFSO=nothing
%>
</table>
I give user type file name.In this picture,I type hello
http://img216.imageshack.us/img216/7996/88101899au7.th.jpg (http://img216.imageshack.us/my.php?image=88101899au7.jpg)
It shows result
http://img212.imageshack.us/img212/4521/83110706ef4.th.jpg (http://img212.imageshack.us/my.php?image=83110706ef4.jpg)
I click only the button that is right of "hello.txt".It shows this
http://img216.imageshack.us/img216/6099/32099936ya2.th.jpg (http://img216.imageshack.us/my.php?image=32099936ya2.jpg)
this picture is my database after I click to open only "hello.txt"
http://img166.imageshack.us/img166/6721/88354076hv8.th.jpg (http://img166.imageshack.us/my.php?image=88354076hv8.jpg)