Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visual Basic uploading files to SharePoint -- error-trapping routine

Status
Not open for further replies.

S3066

Technical User
Aug 1, 2001
66
US
Hi,

This code uses WebDAV to upload files automatically to SharePoint. I didn't write it, though. "Jeff Jones" did.

My question is, the code below doesn't have an error-trapping routine that notifies me, at run-time, if a file didn't successfully get uploaded to SharePoint. Instead, the code is "silent."

Thoughts from anyone on how the code below could be modified to tell the user at run-time if a file didn't get successfully uploaded to SharePoint? Is there a VB solution that I could append to this code?

Again, below is the code. I pulled it from

Thanks,
SL
-----------------------------------------------------------

' Written by Jeff Jones 3-30-2004. Pure freeware, please redistribute.
'=================================

'Use this function call to upload a single file
WebUploadFile "C:\file.txt", "[link=http://server/folder/file.txt][/url]",
"domain\user", "password"

'Use this function call and constant to upload a directory and all it's
subdirectories
Const basedir = "c:\temp"
WebUploadDir "", "[link=http://server/folder/][/url]", "domain\user", "password"

'====================== WebDAV upload single file
Function WebUploadFile (file, url, user, pass)
Dim objXMLHTTP
Dim objADOStream
Dim arrbuffer
Set objADOStream = CreateObject("ADODB.Stream")
objADOStream.Open
objADOStream.Type = 1
objADOStream.LoadFromFile file
arrbuffer = objADOStream.Read()
Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP")
objXMLHTTP.open "PUT", url, False, user, pass
objXMLHTTP.send arrbuffer
End Function

'====================== WebDAV upload directroy
Function WebUploadDir (dir, baseUrl, usr, pwd)
Set fso = CreateObject("Scripting.FileSystemObject")
If dir = "" Then dir = basedir
Set srcFolder = fso.GetFolder(dir)

Dim fl
Set files = srcFolder.files
For Each fl in files
Dim relpath
relpath = Right(fl.path,Len(fl.path)-Len(basedir)-1)
relpath = Replace(relpath, "\", "/")
WebUploadFile fl.path, baseUrl & relpath, usr, pwd
Next

Dim sf
Set subfold = srcFolder.SubFolders
For Each sf in subfold
Set f = fso.GetFolder(sf)
relpath = Right(f,Len(f)-Len(basedir)-1)
relpath = Replace(relpath, "\", "/")
Set objXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP")
objXMLHTTP.open "MKCOL", baseUrl & relpath, False, usr, pwd
objXMLHTTP.send
WebUploadDir f , baseUrl, usr, pwd
Next
End Function
-----------------------------------------------------------
 
The function should return a value. The value should be the result of the objXMLHTTP.send routines. Your base call should evaluate the function return and report success/failure.

I take it that this is VBScript. You'd be better off translating this to VB.NET, which has much more robust error-handling built in, such as Try/Catch blocks.

Phil H.
Some Bank
-----------
Time's fun when you're having flies.
 
Thanks for that tip; I will trace the function call to determine what values to look for in my error trap.

Does anyone have any ideas on how to have the code CREATE the appropriate directory if it doesn't exist?

Appreciate any insights. Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top