我已经使用ADO试验成功了,把代码显示出来给大家参考一下:
里面可能还有不少BUG,希望大家能提点意见,使用的语言是VB6
使用这种方法,不需要数据库的支持,可以直接进行搜索。
可是要引用ADO哦!
最好PKMCDO一同引用一下。
'===================================================================
' searchdocument
' Description: search document in the server
' Arguments: attributes of the object:
' sHref - URL path of the documents(Http://....) your will to find
' title - the title of the document your want find
' author - the author of the document
' createdate_start -- the query document's created date(begindate)
' createdate_end -- the query document's created date(enddate)
'=====================================================================
Function searchdocument(shref As String, Optional department As String, Optional title As String, Optional author As String, Optional keywords As String, Optional createdate_start As Date = #1/1/1975#, Optional createdate_end As Date = #1/1/2035#) As String()
Dim result() As String
If Trim(shref) = "" Then
result() = Split("礚ヴ獺ノ...", "^")
Else
Dim sql As String
sql = "select ""DAV:href"" from scope('DEEP TRAVERSAL OF """ & shref _
& """') where ""urn:schemas-microsoft-com:office:office#creattiondate"" >= '" _
& createdate_start & "' and ""urn:schemas-microsoft-com:office:office#creationdate"" <= '" _
& createdate_end & "'"
If Trim(department) <> "" Then
sql = sql & " and ""urn:schemas-microsoft-com:office:office#department"" like '%" _
& department & "%'"
End If
If Trim(title) <> "" Then
sql = sql & " and ""urn:schemas-microsoft-com:office:office#Title"" like '%" _
& title & "%'"
End If
If Trim(author) <> "" Then
sql = sql & " and ""urn:schemas-microsoft-com:office:office#Author"" like '%" _
& author & "%'"
End If
If Trim(keywords) <> "" Then
sql = sql & " and ""urn:schemas-microsoft-com:office:office#urn:schemas-microsoft-com:publishing:BestBetKeywords"" like '%" & keywords & "%'"
End If
sql = sql & " ORDER BY ""DAV:href"" "
MsgBox "sql: " & sql
On Error Resume Next
'Execute Query
Dim conn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rs As ADODB.Recordset
Set conn = CreateObject("ADODB.Connection")
If Err.Number <> 0 Then
result() = Split(Err.Description, "^")
searchdocument = result()
conn.Close
Exit Function
End If
Set cmd = CreateObject("ADODB.Command")
If Err.Number <> 0 Then
result() = Split(Err.Description, "^")
searchdocument = result()
conn.Close
Exit Function
End If
Set rs = CreateObject("ADODB.RecordSet")
If Err.Number <> 0 Then
result() = Split(Err.Description, "^")
searchdocument = result()
conn.Close
Exit Function
End If
If Err.Number <> 0 Then
result() = Split(Err.Description, "^")
searchdocument = result()
conn.Close
Exit Function
End If
Set cmd.ActiveConnection = conn
cmd.CommandText = sql
If Err.Number <> 0 Then
result() = Split(Err.Description, "^")
searchdocument = result()
conn.Close
Exit Function
End If
rs.Open cmd
If Err.Number <> 0 Then
'MsgBox "rs.open cmd err " & Str(Err.Number) & Err.Description '''''''''''''''''''''''
result() = Split(Err.Description, "^")
searchdocument = result()
conn.Close
Exit Function
End If
'MsgBox "here conntect and run command over,rows: " & rs.Fields.Count '''''''''''''''''''''
Dim j
Dim sResult As String
sResult = ""
Dim i As Integer
i = 0
While Not rs.EOF 'there is no error in it
i = i + 1
If sResult <> "" Then
For j = 0 To rs.Fields.Count - 1
If rs(j).Name = "DAV:href" Then
sResult = sResult & "^" & rs(j).Value
End If
Next
Else
For j = 0 To rs.Fields.Count - 1
If rs(j).Name = "DAV:href" Then
sResult = sResult & rs(j).Value
End If
Next
End If
rs.MoveNext
Wend
result() = Split(sResult, "^")
End If
'MsgBox "rows: " & i '''''''''''''''''''''''''''''
searchdocument = result()
conn.Close
to hgknight(江雨.net) :
我现在用的是SHAREPOINT PORTAL SERVER 所有文件都存于该服务器上,根本就没有什么数据库,若是有数据库我就不会发贴子了!而且我要找的文件根本就只能在WEB路径中找到,在我的SHAREPOINT PORTAL SERVER上,在该SERVER的硬盘上搜索都不行,只能通过SHAREPOINT PORTAL SERVER 的内部搜索引擎搜索才能搜索到文件,我现在是想通过自己写的函数来实现搜索功能。尽管我已经知道文件的WEB路径,但我真不知这搜索引擎怎么写...