下面的VBScript相當多的資源和代碼示例上傳文件使用FrontPage RPC:
Function StringToByteArray(str)
Set stream = CreateObject("ADODB.Stream")
stream.Open
stream.Type = 2 ''adTypeText
stream.Charset = "ascii"
stream.WriteText str
stream.Position = 0
stream.Type = 1 ''adTypeBinary
StringToByteArray = stream.Read()
stream.Close
End Function
Sub UploadFile(sourcePath, siteUrl, docName, title, checkincomment, userName, password)
strHeader = "method=put+document%3a12.0.4518.1016" + _
"&service_name=%2f" + _
"&document=[document_name=" + Escape(docName) + _
";meta_info=[vti_title%3bSW%7c" + Escape(title) + "]]" + _
"&put_option=overwrite,createdir,migrationsemantics" + _
"&comment=" + _
"&keep%5fchecked%5fout=false" + vbLf
bytearray = StringToByteArray(strHeader)
Set stream = CreateObject("ADODB.Stream")
stream.Open
stream.Type = 1 ''adTypeBinary
stream.Write byteArray
Set stream2 = CreateObject("ADODB.Stream")
stream2.Open
stream2.Type = 1 ''adTypeBinary
stream2.LoadFromFile sourcePath
stream2.CopyTo stream, -1
stream.Position = 0
Set xmlHttp = CreateObject("MSXML2.XMLHTTP")
xmlHttp.open "POST", siteUrl + "/_vti_bin/_vti_aut/author.dll", false, userName, password
xmlhttp.setRequestHeader "Content-Type","application/x-vermeer-urlencoded"
xmlhttp.setRequestHeader "X-Vermeer-Content-Type","application/x-vermeer-urlencoded"
xmlhttp.setRequestHeader "User-Agent", "FrontPage"
xmlHttp.send stream
If xmlHttp.status = 200 Then
If Instr(xmlHttp.responseText, "successfully") = 0 Then
MsgBox "ERROR: " & vbCrLf & xmlHttp.responseText
Else
''Checkin
strHeader = "method=checkin+document%3a12.0.4518.1016" + _
"&service_name=%2f" + _
"&document_name=" & Escape(docName) + _
"&comment=" + Escape(checkincomment) + _
"&keep%5fchecked%5fout=false" + vbLf
Set xmlHttp = CreateObject("MSXML2.XMLHTTP")
xmlHttp.open "POST", siteUrl + "/_vti_bin/_vti_aut/author.dll", false, userName, password
xmlhttp.setRequestHeader "Content-Type","application/x-vermeer-urlencoded"
xmlhttp.setRequestHeader "X-Vermeer-Content-Type","application/x-vermeer-urlencoded"
xmlhttp.setRequestHeader "User-Agent", "FrontPage"
xmlHttp.send strHeader
End If
End If
If xmlHttp.status/100 <> 2 Then
MsgBox "ERROR: status = " & xmlHttp.status & vbCrLf & xmlHttp.responseText
End If
End Sub
UploadFile "C:\Users\myusername\Desktop\Test File.zip", _
"http://computername/Sites/sitename", _
"Requirements/Test File.zip", _
"Test title", _
"Test checkin comment", _
"MYDOMAIN\myusername", "mypassword"
MsgBox "Done"
請注意文件名應該只包含ASCII字符。否則,上面的腳本將不起作用。
謝謝你這麼多!這正是我所需要的。我已經有了'插入'並正在工作。我現在唯一的問題是:如何設置其他metedata字段的值?示例...我們需要在上傳時爲每個文檔提供描述和項目名稱...因此,我如何設置該設置? – user457338 2010-09-28 01:26:13
在上面的腳本中,添加了元數據「vti_title」。您可以通過在meta_info = []括號內添加更多的元數據屬性。例如。 ' 「; meta_info = [vti_title%3bSW%7C」 +逃生(標題)+ 「;項目%3bSW%7C」 +逃生(項目)+ 「]]」'。您必須在文檔庫中有一個名爲'project'的自定義字段。 「SW」意味着它必須是一個字符串值(布爾使用「BW」(真/假),或「IW」爲整數)。 – 2010-09-28 05:24:20