I am using xmlhttp via VBscript to upload files to a sharepoint directory. I know there are much better ways to do this but I have several constraints that have forced this solution. I have been able to decode a base 64 file properly, write it to a file (i.e. spreadsheet, PDF, etc.) on my hard drive and it opens fine and the file size is correct. However, when I use the following code to upload the the file it shows up on the sharepoint but the size is inflated by several hundred to several thousand bytes and the file is corrupt. I have tried setting the content-length, etc. and checking my MSXML instantantiations but nothing is working. Here is the code snippet:
Strlen1 = previously calculated size of the file. It has already been written and is now being opened to upload. This two-step process is for debugging only.
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oTextStream = oFS.OpenTextFile(fname1,1)
sFileContents = oTextStream.Read(strlen1)
xmlHttp.Open "PUT","http://sharepoint url/" & fname, false
' xmlHttp.setRequestHeader "Content-Length",strlen1
xmlHttp.Send SfileContents
XmlHttp.onreadystatechange = getref("HandleStateChange")
As I mentioned, the file contents are sent to the sharepoint and put in the correct file but the file size seems to be padded with characters and I don't know how to stop this. A clue I received was that when I used msxml2.xmlhttp.3.0 or I could not create a file size greater than 1Kbyte on the Sharepoint with this method. Once I switched to msxml2.xmlhttp.4.0 it worked. I have tried msxml2.xmlhttp.5.0 and msxml2.xmlhttp.6.0 but they don't seem to have any effect on this problem. I included the SetRequestHeader statement with the content length (even though it is commented out) to show I have tried this but with no effect. I have also tried using "Post" but it never seems to write a file even if the post is successful.
Any clues or hints on what is happening would be greatly appreciated.