Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Publish to Sharepoint

Status
Not open for further replies.

Rseven

Technical User
Mar 7, 2006
41
US
Hello All,
Below is some code I have in MS Access 2007 VBA that uploads documents to our SharePoint site. It works perfectly with one exception. What I would like it to do once it is loaded to the site is to be placed in a master document library that is grouped by the report name. The report name is housed in a sharepoint field (FieldName="Report", FieldInternalName="Report", FieldType="SPFieldChoice") in which I have the GUID ('WPQ21d00fde5-84eb-4782-8dfc-d9b96a0400e7Report'). I would greatly appreciate any input at all.

thanks in advance!

Public Sub CopyToSharePoint()
On Error GoTo err_Copy
Dim xmlhttp
Dim sharepointUrl
Dim sharepointFileName
Dim tsIn
Dim sBody
Dim LlFileLength As Long
Dim Lvarbin() As Byte
Dim LobjXML As Object
Dim LstrFileName As String
Dim LvarBinData As Variant
Dim PstrFullfileName As String
Dim PstrTargetURL As String
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim fldr As Folder
Dim f As File
Dim pw As String
Dim UserName As String
Dim RetVal
Dim I As Integer
Dim totFiles As Integer
Dim Start As Date, Finish As Date

sharepointUrl = "[http path to server]/[server folder to write to]"
Set LobjXML = CreateObject("Microsoft.XMLHTTP")
Set fldr = fso.GetFolder(CurrentProject.Path & "\[folder with files to upload]\")
totFiles = fldr.Files.Count
For Each f In fldr.Files
sharepointFileName = sharepointUrl & f.Name
PstrFullfileName = CurrentProject.Path & "\[folder with files to upload]\" & f.Name
LlFileLength = FileLen(PstrFullfileName) - 1
' Read the file into a byte array.
ReDim Lvarbin(LlFileLength)
Open PstrFullfileName For Binary As #1
Get #1, , Lvarbin
Close #1
' Convert to variant to PUT.
LvarBinData = Lvarbin
PstrTargetURL = sharepointUrl & f.Name

' Put the data to the server, false means synchronous.
LobjXML.Open "PUT", PstrTargetURL, False
' Send the file in.
LobjXML.Send LvarBinData
End If

I = I + 1
RetVal = SysCmd(acSysCmdSetStatus, "File " & I & " of " & totFiles & " copied...")

Next f
RetVal = SysCmd(acSysCmdClearStatus)
Set LobjXML = Nothing
Set fso = Nothing

err_Copy:
If Err <> 0 Then
MsgBox Err & " " & Err.Description
End If
End Sub
 
What's not working? You say "it works perfectly with one exception.", what is it?

Also, it might be an issue dealing with SharePoint of checking-in the document. The document may be there, but you may not be able to manipulate it until you check it in outside of the macro. You may need to perform the process you want before uploading it to the SharePoint site.
 
Ok, so the document gets posted to the sharepoint site, hence the working perfectly. The exception is, the library it gets posted to is Grouped by a field named "Report". When it gets uploaded, it is Grouped under a blank report type because the "Report" is not specified at the time of the upload. So, what I am trying to do is programatically populate the "Report" field with the report name, (i.e. Weekly Issue Report) so it gets grouped with its proper report group. Basically, I am trying to do it without having to go out to SharePoint and manually update the record.

Below is how the Page is displayed and grouped (number in parenthesis is the number of reports in that group):

Report: Audit Report (21)
Report: CEC (2)
Report: Issue Data Quality Report (6)
Report: TS Weekly Highlights (6)
Report: Weekly Issue Report (13)

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top