问题描述
我正在尝试在 SSIS 2005 中开发一个包,我的部分过程是检查网络上的文件是否为空.如果它不为空,我需要传递一个成功的状态,否则我需要传递一个不成功的状态.我想我需要一个脚本任务,但不知道如何去做.任何帮助表示赞赏.
I am trying to develop a package in SSIS 2005 and part of my process is to check if a file on the network is empty or not. If it is not empty, I need to pass a status of successful, otherwise, I need to pass a status of unsuccessful. I think I need a script task, but am not sure how to go about it. Any help is appreciated.
推荐答案
是的,脚本任务将在这里完成这项工作.在脚本顶部添加 using System.IO 语句,然后 Main 方法中的以下内容将检查文件的内容.
Yes, a Script task will do the job here. Add a using System.IO statement to the top of the script, then something along the lines of the following in the Main method will check the contents of the file.
public void Main()
{
String FilePath = Dts.Variables["User::FilePath"].Value.ToString();
String strContents;
StreamReader sReader;
sReader = File.OpenText(FilePath);
strContents = sReader.ReadToEnd();
sReader.Close();
if (strContents.Length==0)
MessageBox.Show("Empty file");
Dts.TaskResult = (int)ScriptResults.Success;
}
2005 年的 VB.Net 版本...
VB.Net version for 2005...
Public Sub Main()
Dim FilePath As String = Dts.Variables("User::FilePath").Value.ToString()
Dim strContents As String
Dim sReader As StreamReader
sReader = File.OpenText(FilePath)
strContents = sReader.ReadToEnd()
sReader.Close()
If strContents.Length = 0 Then
MessageBox.Show("Empty file")
End If
Dts.TaskResult = ScriptResults.Success
End Sub
这篇关于确定文件是否为空 (SSIS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!