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!

Load a file to Sharepoint

Status
Not open for further replies.

FractalWalk

Technical User
Nov 18, 2002
141
US
I need to be able to replace a text file to an existing folder on a Sharepoint site using VBA. Due to network admin constraints, I can not use a shared drive solution and the site itself requires a username login and password.

When I search the web (and this site) the solutions tend to be identifying the folder's URL path and using that to copy the file. However, I can not use FileCopy as the site rquires authentication. I tried a FileSystemObject method but evidently that does not work for web address (folder not found) and I probably would have authentication issues as well.

Can anyone point me in the right direction?
 
Of course after days of researching I finally post and then find my own answer a few minutes later. I located a refernce to Microsoft.XMLHTTP. Not exatly sure what it is but it works.

Code:
    UserName = [I will setup a menu for this]
    pw = [I will setup a menu for this]
    sharepointUrl = [URL of folder]
    Set LobjXML = CreateObject("Microsoft.XMLHTTP")
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fldr = fso.GetFolder(Sourcefolder)
    For Each f In fldr.Files
        sharepointFileName = sharepointUrl & f.Name
        If sharepointFileName Like "*.txt" Then
            Set tsIn = f.OpenAsTextStream
            sBody = tsIn.ReadAll
            tsIn.Close
            Set xmlhttp = CreateObject("MSXML2.XMLHTTP.4.0")
            xmlhttp.Open "PUT", sharepointFileName, False, UserName, pw
            xmlhttp.Send sBody
        End If
    Next f
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top