允许上载的SharePoint文件标记为“已签入”

时间:2014-04-21 20:24:50

标签: sharepoint vbscript

我刚写了一个将文件上传到共享文件夹的vbscript。有用。问题是这些文件的默认状态是“Check Out”。所以我必须在前端手动选择这些文件为“Check In”。我认为这违背了我的剧本的目的。有没有解决的办法?任何帮助都感激不尽。谢谢。 杰克

P.S。这是一个示例代码。

URL = "http://portal/projects/"
Set objXMLHTTP = CreateObject("Msxml2.ServerXMLHTTP.3.0")
Set objADOStream = CreateObject("ADODB.Stream")
    With objADOStream
        .Open
        .Type = 1
        .LoadFromFile ("C:\VBScripts\SP\2014_Test_IC.txt")
    End With
content = objADOStream.Read
objXMLHTTP.open "PUT",URL & "2014_Test_IC.txt",False,"Username","Password"
objXMLHTTP.send content
WScript.Echo objXMLHTTP.status & ":" & objXMLHTTP.statusText
objADOStream.Close

2 个答案:

答案 0 :(得分:2)

可以使用Front Page Server Extensions完成此操作。

以下是签入文档方法的官方文档:http://msdn.microsoft.com/en-us/library/dd585532%28v=office.11%29.aspx

这是用于上传然后签入文档的代码。它与你的非常相似,你可以看到在调用上传功能时你会在哪里填写你的值。

  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"

我需要赞扬fmunkert解决这个问题:VBScript to Upload file to SharePoint DocLib

答案 1 :(得分:0)

不完全确定您运行的哪个sharepoint服务器版本....或者通过在此特定示例中应用KnowledgeVersion.CheckIn方法将成功,但这里是一个测试源代码,无论如何都可以尝试。

  

Checkin方法检入当前文档。登记入住   签出时对文档进行编辑预约   并更新文档的内容。

Dim URL, objXMLHTTP, objADOStream
Dim content, Version

URL = "http://portal/projects/"
Set objXMLHTTP = CreateObject("Msxml2.ServerXMLHTTP.3.0")
Set objADOStream = CreateObject("ADODB.Stream")
    With objADOStream
        .Open
        .Type = 1
        .LoadFromFile ("C:\VBScripts\SP\2014_Test_IC.txt")
    End With
Set Version = CreateObject("CDO.KnowledgeVersion")
Version.Checkin URL & "2014_Test_IC.txt"
content = objADOStream.Read
objXMLHTTP.open "PUT",URL & "2014_Test_IC.txt",False,"Username","Password"
objXMLHTTP.send content
WScript.Echo objXMLHTTP.status & ":" & objXMLHTTP.statusText
objADOStream.Close