Solved

SharePoint 2010: xmlhttp file uploads fail

Posted on 2011-02-17
6
1,109 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
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.

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now