Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8491

Re: Uploading documents to sharepoint using RedWood \ CPS

$
0
0

Hi Sjoerd,

 

This means that it might be easier to use VBScript for this, since we cannot load the WSDL from the sharepoint server.

 

You can use the following code:

 

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 FilePath, _

    SiteURL, _

    SharePointPath, _

    FileTitle, _

    CheckinComment, _

   DomainUser, DomainUserPassword


Wscript.echo "Sucessfully uploaded file."

 

 

Create a VBS job definition with the above source and the following String parameters:

 

SiteURL is something like: "http://computername/Sites/sitename"

SharePointPath is something like "Requirements/Test File.zip"

FileTitle is the title, example: "Test File Uploaded from CPS"

CheckinComment is a comment for the checkin, e.g. "Test File Uploaded from CPS"

DomainUser is something like "MYDOMAIN\myusername"

DomainUserPassword is the password, make this a password parameter.

 

Since I do not have a sharepoint server around, I had to grab this from the following website - I have not tested it but apparently, some users claim it works:

 

VBScript to Upload file to SharePoint DocLib - Stack Overflow

 

Regards,

 

HP


Viewing all articles
Browse latest Browse all 8491

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>