davincith
09-18-2007, 05:57 PM
I write search files webpage.when users enter part or all of a file name and asp page send back a list of only the files(that user can click to open files) whose names contain the text they entered.I want to save data about accessing files such as file name ,accessed date of fileto my database(Microsoft Access) after user click to open the file.I don't know how to write a adding code to do this.
This my asp code.please tell me how to solve.
<%
Dim strPath ' Path of directory to search
Dim objFSO ' FileSystemObject variable
Dim objFolder ' Folder variable
Dim objItem ' Variable used to loop through the
'contents of the folder
Dim strQuery ' Search string
' You could just as easily read this from some sort of input,
' but I don't need you guys roaming around our server so
' I've hard coded it to a directory I set up to illustrate
' the sample.
' NOTE: As currently implemented, this needs to end with the /
strPath = "c:\uploaded files"
' Retrieve the search string. If empty it will return all files.
strQuery = Request.QueryString("query")
' Show our search form and a few links to some sample searches
' Create our FSO and get a handle on our folder
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Server.MapPath(strPath))
' Show a little description line and the title row of our table
%>
<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><font color="#FFFFFF"><strong>File Size:</strong></font></td>
<td><font color="#FFFFFF"><strong>Date Created:</strong></font></td>
</tr>
<%
' Now come the part where we find the files whose names match the string
' passed in part. It's relatively straightforward. We simply loop through
' the objFolder.Files collection and check each file's name to see if it
' matches. Note that I'm not going to look for SubFolders that match our
' search string. You can easily include them if you like. Just use
' objFolder.SubFolders. The syntax is the same as it is for files.
For Each objItem In objFolder.Files
' I'm using a case insensitive search. If you want case sensitivity
' then change vbTextCompare to vbBinaryCompare
If InStr(1, objItem.Name, strQuery, vbTextCompare) <> 0 Then
%>
<tr bgcolor="#CCFFCC">
<td align="left" ><a href="<%= strPath & objItem.Name %>"><%= objItem.Name %></a></td>
<td align="right"><%= objItem.Size %></td>
<td align="left" ><%= objItem.DateCreated %></td>
</tr>
<%
End If
Next 'objItem
' All done! Kill off our object variables.
Set objItem = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
%>
</table>
This my asp code.please tell me how to solve.
<%
Dim strPath ' Path of directory to search
Dim objFSO ' FileSystemObject variable
Dim objFolder ' Folder variable
Dim objItem ' Variable used to loop through the
'contents of the folder
Dim strQuery ' Search string
' You could just as easily read this from some sort of input,
' but I don't need you guys roaming around our server so
' I've hard coded it to a directory I set up to illustrate
' the sample.
' NOTE: As currently implemented, this needs to end with the /
strPath = "c:\uploaded files"
' Retrieve the search string. If empty it will return all files.
strQuery = Request.QueryString("query")
' Show our search form and a few links to some sample searches
' Create our FSO and get a handle on our folder
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Server.MapPath(strPath))
' Show a little description line and the title row of our table
%>
<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><font color="#FFFFFF"><strong>File Size:</strong></font></td>
<td><font color="#FFFFFF"><strong>Date Created:</strong></font></td>
</tr>
<%
' Now come the part where we find the files whose names match the string
' passed in part. It's relatively straightforward. We simply loop through
' the objFolder.Files collection and check each file's name to see if it
' matches. Note that I'm not going to look for SubFolders that match our
' search string. You can easily include them if you like. Just use
' objFolder.SubFolders. The syntax is the same as it is for files.
For Each objItem In objFolder.Files
' I'm using a case insensitive search. If you want case sensitivity
' then change vbTextCompare to vbBinaryCompare
If InStr(1, objItem.Name, strQuery, vbTextCompare) <> 0 Then
%>
<tr bgcolor="#CCFFCC">
<td align="left" ><a href="<%= strPath & objItem.Name %>"><%= objItem.Name %></a></td>
<td align="right"><%= objItem.Size %></td>
<td align="left" ><%= objItem.DateCreated %></td>
</tr>
<%
End If
Next 'objItem
' All done! Kill off our object variables.
Set objItem = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
%>
</table>