Solved

SharePoint 2010: xmlhttp file uploads fail

Posted on 2011-02-17
6
1,191 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
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.

739 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