Solved

SharePoint 2010: xmlhttp file uploads fail

Posted on 2011-02-17
6
1,129 Views
Last Modified: 2012-05-11
I have used the attached VBA code siccessfully in other applications to upload xml and html files to other instances of Sharepoint, but in a new Sharepoint 2010 installation the uploaded files appear to be processing correctly, and the procedure completes without error, but the files are not being written to the destination SP folder. The SP admin tells me that that he knows of no SP settings that might prevent writing to the folder programmatically, and that the folder is email enabled (if that is relevant here). Does anybody have any suggestions?
Public Sub CopyToSharePoint()

On Error GoTo err_Copy

Dim xmlhttp
Dim sharepointUrl
Dim sharepointFileName
Dim tsIn
Dim sBody
Dim LobjXML As Object
Dim UserName As String
Dim pw As String
Dim RetVal
Dim i As Integer
Dim TotFiles As Integer
Dim Start As Date, Finish As Date
Dim fso As New Scripting.FileSystemObject
Dim fldr As folder
Dim f As File

Set fldr = fso.GetFolder("c:\FilesToUpload\")

UserName = DLookup("[Username]", "tbl_UserData")
pw = DLookup("[Password]", "tbl_UserData")
sharepointUrl = "http://domain.server.com/Project/DestFolder/"

Set LobjXML = CreateObject("Microsoft.XMLHTTP")

TotFiles = fldr.Files.Count

For Each f In fldr.Files

 sharepointFileName = sharepointUrl & f.Name

    Set tsIn = f.OpenAsTextStream
    sBody = tsIn.ReadAll
    tsIn.Close

    Set xmlhttp = CreateObject("MSXML2.XMLHTTP.6.0")

    xmlhttp.Open "PUT", sharepointFileName, False, UserName, pw

    xmlhttp.Send sBody

  i = i + 1

  RetVal = SysCmd(acSysCmdSetStatus, "File " & i & " of " & TotFiles & " copied...")

Next f

   RetVal = SysCmd(acSysCmdClearStatus)

  Set LobjXML = Nothing

  Set fso = Nothing

err_Copy:

MsgBox Err & " " & Err.Description

If Err <> 0 Then
  MsgBox Err & " " & Err.Description
  Resume Next
End If

End Sub

Open in new window

0
Comment
Question by:dgmoore1
  • 4
  • 2
6 Comments
 
LVL 3

Expert Comment

by:AndrewSkoraro
ID: 34946633
Check to see if versioning is on and if so, are you creating unpublished versions?
0
 

Author Comment

by:dgmoore1
ID: 34946775
I'm not sure what you mean by unpublished versions. The uploaded files are updated daily in most cases, and overwrite whatever is currently in the folder. There is no intention of maintaining different versions of the same files. In any case, the folder I'm trying to write to is currently empty so there would be no conflict between uploaded files and files with the same names that are already present.
0
 

Author Comment

by:dgmoore1
ID: 34954272
I just added MsgBox xmlhttp.status after the xmlhttp.send statement. I'm getting 401 Access denied. The credentials I'm passing are valid - any idea what could be preventing access?
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 3

Expert Comment

by:AndrewSkoraro
ID: 34955300
If versioning is on, then changes will not go into effect (viewable by read only users) until a published or full version is checked in.

Check to see what security settings are enabled in IIS.  I suspect that basic auth was turned on previously and now it is not.
0
 

Accepted Solution

by:
dgmoore1 earned 0 total points
ID: 34955377
I discovered the problem - the credentials passed to the server must include the domain. When I added the domain to the credentials everything clicked.
0
 

Author Closing Comment

by:dgmoore1
ID: 34990850
I found the solution myself
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question