Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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


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 http://www.visualbasicscript.com/m_41740/tm.htm.


' 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]http://server/folder/file.txt[/link]",
 "domain\user", "password"
 'Use this function call and constant to upload a directory and all it's
 Const basedir = "c:\temp"
 WebUploadDir "", "[link=http://server/folder/]http://server/folder/[/link]", "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.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
   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
       WebUploadDir f , baseUrl, usr, pwd
  End Function

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

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.

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

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close