Solved

SharePoint 2010: xmlhttp file uploads fail

Posted on 2011-02-17
6
1,091 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Note:  There are two main ways to deploy InfoPath forms:  Server-side and directly through the SharePoint site.  Deploying a server-side InfoPath form means the form is approved by the Administrator, thus allowing greater functionality in the form. …
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

758 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

22 Experts available now in Live!

Get 1:1 Help Now