2011-10-19 75 views
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 

回答

0

我剛剛這個問題,並發現,使用常規的顯然是過時的版本爲每代碼工作如下設置文檔的元信息工作確定:

Public Sub SetSPMetaData(ByVal sURL As String, ByVal sDocName As String, ByVal sTitle As String, _ 
        Optional ByVal OriginalPath As String, Optional ByVal OriginalName As String, _ 
        Optional ByVal ModDate As Date, Optional ByVal FileID As Long) 

Dim strHeader As String 
Dim byteArray() As Byte 
Dim stream As New ADODB.stream 
Dim stream2 As New ADODB.stream 
Dim xmlHTTP As New MSXML2.xmlHTTP 
Dim sTempFile As String 
Dim UserName As String 
Dim Password As String 


On Error GoTo SetSPMetaData_Error 

'Method = setDocsMetaInfo: server_extension_version 
'&service_name=/[&listHiddenDocs=(true|false)] 
'&listLinkInfo=(true|false)&url_list=list_of_urls 
'&metaInfoList=(list_of_meta_info)[&errorFlags=(KeepGoing|StopOnFirst)] 


'POST /site_url/_vti_bin/_vti_aut/author.dll HTTP/1.0 
'. 
'. 
'. 
'method=set+docs+meta+info:6.0.n.nnnn 
'&service_name=/ 
'&url_list=[List_Name/File_Name] 
'&metaInfoList=[[vti_title;SR|Web+Settingt;SW|fp40]]true 
'&listLinkInfo=true 

If OriginalPath = "" And OriginalName = "" Then 
    strHeader = "method=set+document+meta-info:6.0.n.nnnn" + _ 
       "&service_name=/&document_name=" & sDocName & _ 
       "&meta_info=[vti_title;SR|" & Replace(Escape(sTitle), "%5C", "%5C%5C") & "]" 
Else 

    If OriginalName = "" Then 
     If CLng(ModDate) = 0 Then 

      strHeader = "method=set+document+meta-info:6.0.n.nnnn" + _ 
         "&service_name=/&document_name=" & sDocName & _ 
         "&meta_info=[vti_title;SR|" & Replace(Escape(sTitle), "%5C", "%5C%5C") & _ 
         ";Original Path;SR|" & Replace(Escape(OriginalPath), "%5C", "%5C%5C") & "]" 


     Else 

      strHeader = "method=set+document+meta-info:6.0.n.nnnn" + _ 
         "&service_name=/&document_name=" & sDocName & _ 
         "&meta_info=[vti_title;SR|" & Replace(Escape(sTitle), "%5C", "%5C%5C") & _ 
         ";Original Modified|" & Format(ModDate, "DD MMM YYYY hh:mm:ss") & _ 
         ";Original Path;SR|" & Replace(Escape(OriginalPath), "%5C", "%5C%5C") & "]" 

     End If 

    Else 

     If CLng(ModDate) = 0 Then 
      strHeader = "method=set+document+meta-info:6.0.n.nnnn" + _ 
         "&service_name=/&document_name=" & sDocName & _ 
         "&meta_info=[vti_title;SR|" & Replace(Escape(sTitle), "%5C", "%5C%5C") & _ 
         ";Original Name;SR|" & Replace(Escape(OriginalName), "%5C", "%5C%5C") & _ 
         ";Original Path;SR|" & Replace(Escape(OriginalPath), "%5C", "%5C%5C") & "]" 
     Else 

      strHeader = "method=set+document+meta-info:6.0.n.nnnn" + _ 
         "&service_name=/&document_name=" & sDocName & _ 
         "&meta_info=[vti_title;SR|" & Replace(Escape(sTitle), "%5C", "%5C%5C") & _ 
         ";Original Name;SR|" & Replace(Escape(OriginalName), "%5C", "%5C%5C") & _ 
         ";Original Modified;TW|" & Format(ModDate, "DD MMM YYYY hh:mm:ss") & _ 
         ";Original Path;SR|" & Replace(Escape(OriginalPath), "%5C", "%5C%5C") & "]" 

     End If 
    End If 
End If 

byteArray = StringToByteArray(strHeader) 

'Set stream = CreateObject("ADODB.Stream") 

If gConfig.GetConfig("frmHTTPAuthentication") = 2 Then 
    If gConfig.GetConfig("txtUserPassword") <> "" Then Password = gConfig.GetConfigDecrypt("txtUserPassword") 
    If gConfig.GetConfig("txtUserName") <> "" Then UserName = gConfig.GetConfigDecrypt("txtUserName") 
End If 

stream.Open 
stream.Type = 1 ''adTypeBinary 
stream.Write byteArray 


stream.Position = 0 
'stream.SaveToFile "C:\StreamContent.txt" 

xmlHTTP.Open "POST", sURL + "/_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, "osstatus=0") <> 0 Then 
     '230    MsgBox "Error - " & cleanup_html(xmlHTTP.responseText) 
     Call LogErrorFilFol(GetFileFromPath(sURL), GetFolderFromPath(sURL), _ 
          "SetSPMetaData - osstatus = 0 - " & cleanup_html(xmlHTTP.responseText), FileID) 
    End If 
    '260   Debug.Print xmlHTTP.responseText 

Else 

    Call LogErrorFilFol(GetFileFromPath(sURL), GetFolderFromPath(sURL), "SetSPMetaData - Status = " & xmlHTTP.Status, FileID) 

End If