【发布时间】:2019-02-09 19:34:10
【问题描述】:
我需要使用 SSIS 中的脚本任务删除 Sharepoint 文件。在 Visual Basic 中,我尝试将 SPListItemCollection 与导入 Microsoft.Sharepoint 一起使用,但它无法识别命名空间。我没有找到很多关于这个主题的线程,或者我发现的内容与脚本任务无关,所以任何帮助都将不胜感激。非常感谢
根据@Hadi 回答更新
感谢哈迪的回答。我已经放弃了使用 SPListCollection 的想法,因为它看起来太复杂了。相反,我试图在将文件从 Sharepoint 下载到本地文件夹后删除该文件。我需要在实际删除文件的那一行获得帮助。这是代码:
Public Sub Main()
Try
' get location of local folder
Dim dir As DirectoryInfo = New DirectoryInfo(Dts.Variables("DestP").Value.ToString())
If dir.Exists Then
' Create the filename for local storage
Dim file As FileInfo = New FileInfo(dir.FullName & "\" & Dts.Variables("FileName").Value.ToString())
If Not file.Exists Then
' get the path of the file to download
Dim fileUrl As String = Dts.Variables("SHP_URL").Value.ToString()
If fileUrl.Length <> 0 Then
Dim client As New WebClient()
If Left(fileUrl, 4).ToLower() = "http" Then
'download the file from SharePoint
client.Credentials = New System.Net.NetworkCredential(Dts.Variables("$Project::UserN").Value.ToString(), Dts.Variables("$Project::Passw").Value.ToString())
client.DownloadFile(fileUrl.ToString() & "/" & Dts.Variables("FileName").Value.ToString(), file.FullName)
Else
System.IO.File.Copy(fileUrl.ToString() & Dts.Variables("FileName").Value.ToString(), file.FullName)
End If
'delete file from Sharepoint
client.(fileUrl.ToString() & "/" & Dts.Variables("FileName").Value.ToString(), file.FullName).delete()
Else
Throw New ApplicationException("EncodedAbsUrl variable does not contain a value!")
End If
End If
Else
Throw New ApplicationException("No ImportFolder!")
End If
Catch ex As Exception
Dts.Events.FireError(0, String.Empty, ex.Message, String.Empty, 0)
Dts.TaskResult = ScriptResults.Failure
End Try
Dts.TaskResult = ScriptResults.Success
End Sub
【问题讨论】:
-
您是否在脚本任务中添加了
Microsoft.Sharepoint.dll作为参考? -
我提供了一个更新,希望它能正常工作
-
下次您应该对我的回答发表评论以通知我您已更新问题,在问题中写入时不会通知我
标签: vb.net sharepoint ssis etl script-task