?
Solved

SharePoint 2010: xmlhttp file uploads fail

Posted on 2011-02-17
6
Medium Priority
?
1,241 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

801 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