Hi,
I created an ssis package to download excel files from sharepoint to a dir, but I am very new with sharepoint connections and website authentication issues, so I ran into the error message below.
Can anyone help me to identify the source of the problem here? Here is the code I use in my script task. Any help would be greatly appreciated.
Thank you!
Script Task Code:
PublicSub Main()
'
' Add your code here
'
' Get the unmanaged connection object, from the connection manager called "HTTP Connection Manager"
Dim nativeObjectAsObject = Dts.Connections("HTTP_ConnectionManager").AcquireConnection(Nothing)
' Create a new HTTP client connection
Dim passedFileNameAsString = Me.Dts.Variables.Item(0).Value.ToString
passedFileName = Replace(passedFileName,
":","_") & ".xlsx"
Dim connectionAsNew HttpClientConnection(nativeObject)
connection.ServerURL =
"https://www.mywebsite.com/wo/Part1%20Reporting%20Task%20Item%20File%20Upload/"& passedFileName& "?noredirect=true"
'Dim file As String = Me.Dts.Variables.Item
' Download the file #1
' Save the file from the connection manager to the local path specified
'https://www.mywebsite.com/wo/Part1%20Reporting%20Task%20Item%20File%20Upload/Forms/AllItems""
Dim pathAsString = connection.ServerURL.ToString
Dim filenameAsString = Right(path, Len(path) - InStrRev(path,"/"))
filename = Left(filename, InStr(filename,"?") - 1)
filename = Replace(filename,"%20", " ")
filename = passedFileName
Dim directoryAsString = "C:\SSIS\Test\"
Dim pathandfileAsString = directory & filename connection.DownloadFile(pathandfile,True)
' Confirm file is there
IfFile.Exists(pathandfile) Then
' MessageBox.Show(String.Format("File {0} has been downloaded.", pathandfile))
EndIf
' Download the file #2
' Read the text file straight into memory
Dim bufferAsByte() = connection.DownloadData()
Dim dataAsString = Encoding.ASCII.GetString(buffer)
' Display the file contents' MessageBox.Show(data)
Dts.TaskResult =
ScriptResults.Success
EndSub
End Close
This is the error message:
at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes,
RuntimeType typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
Error: 0xC001600E at WorkOrderPayItems, Connection manager "HTTP_ConnectionManager":
Server returned status code - 404 : NOT FOUND. This error occurs when the server is experiencing problems.
Error: 0x1 at Script Task 1: Exception has been thrown by the target of an invocation.
Task failed: Script Task 1