1
將文件上載到SharePoint我正在使用以下VB腳本和前端頁面RPC調用,以將在腳本中配置的文檔及其透視元數據值上載到Sharepoint 2007和2010網站。但是,擴展名爲* .xlsx或* .docx的文件不會使用此腳本上傳其元數據。使用RPC(Vbscript)
在研究了各種網站之後,似乎是_vti_aut/author.dll處理WSS 3.0中新的開放式辦公格式的一個問題。一些建議是在文件上傳到SharePoint網站後使用SetDocsMetaInfo方法。
問題是,我不明白如何使用此方法與此腳本。當我嘗試使用它時,我能夠使用正確的元數據上傳* .xlsx或* .docx文件,但隨後文件被損壞。
我研究過的一些網站已經建議它可能是文件編碼的方式,但我並不那麼熟悉編碼以準確排除故障。
有人可以提供一些關於如何使用此方法(SetDocsMetaInfo)與下面的腳本或使用此腳本提供解決此問題的示例?
這個劇本當初從這個網站檢索:
UploadFile "C:\Test\Work\temp\defer\testDoc_083011.xlsx", _
"http://sharepoint.domainname.com/Sites/SITE1", _
"TestImport/folder1/testDoc_083011.xlsx_083011.xlsx", _
"Test", _
"Test checkin comment", _
"", ""
MsgBox "Done"
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) + ";Business Unit%3bSW%7c" + Escape("Business Unit")+ "]]" + _
"&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