我在 SSIS 2012 的脚本任务中包含以下代码。
public void Main()
{
string inputDir = (string) Dts.Variables["User::InputDirectory"].Value;
string CSVFolder = (string) Dts.Variables["User::CSVFolder"].Value;
string XMLFolder = (string) Dts.Variables["User::XMLFolder"].Value;
string XLSXFolder = (string) Dts.Variables["User::XLSXFolder"].Value;
bool isXMLFolderEmpty = (bool) Dts.Variables["User::isXMLFolderEmpty"].Value;
bool isCSVFolderEmpty = (bool)Dts.Variables["User::isCSVFolderEmpty"].Value;
bool isXLSXFolderEmpty = (bool)Dts.Variables["User::isXLSXFolderEmpty"].Value;
string[] fileNames = Directory.GetFiles(@inputDir);
if (fileNames.Length > 0)
{
foreach (string inputFile in fileNames)
{
string FileExtension = Path.GetExtension(inputFile);
if (FileExtension == ".csv")
{
File.Move(inputDir + "\\" + inputFile, CSVFolder + "\\" + inputFile);
isCSVFolderEmpty = false;
}
else if (FileExtension == ".xlsx")
{
File.Move(inputDir + "\\" + inputFile, XLSXFolder + "\\" + inputFile);
isXLSXFolderEmpty = false;
}
else if (FileExtension == ".xml")
{
File.Move(inputDir + "\\" + inputFile, XMLFolder + "\\" + inputFile);
isXMLFolderEmpty = false;
}
}
}
Dts.TaskResult = (int)ScriptResults.Success;
}
但是,当我执行脚本任务时,我收到以下错误:DTS 脚本任务在用户代码中遇到异常:调用目标已引发异常。
谁能指出出了什么问题?所有变量名都是正确的。