c# - SSIS 包脚本任务输出文件到新文件夹

标签 c# sql-server ssis etl script-task

我正在使用 SSIS 和 C# 中的脚本任务。

我有一个 FOR EACH 循环,它查看文件夹并将找到的每个文件的完整路径和文件名分配给名为 FileNameFound 的变量,然后将其分配给名为 的变量>脚本任务中的文件路径

我还有一个存储输出路径的项目参数,该参数被分配给脚本任务中的“newFilepath”。

然后我使用一些其他代码加密 csv 文件。

底线是,我需要将输出放入与找到它的位置不同的文件夹中,但保留相同的文件名。

例如

  • 查找文件:c:\folder\test.csv
  • 加密并输出到c:\folder\newfolder\test.csv

我需要 newFilepath 作为变量 $Project::CSV_OutputFolder + test.csv

我正在尝试合并 GetFileNameWithoutExtension(String) 但不断收到错误:

The name 'GetFileNameWithoutExtension' does not exist in the current context

这是我的代码:

public void Main()
{
    // Get the filepath of the file that needs to be encrypted.  
    string filepath = Dts.Variables["FileNameFound"].Value.ToString();

    // build output path
    string newFilepath = Dts.Variables["$Package::$Project::CSV_OutputFolder"].Value.ToString() + GetFileNameWithoutExtension(Dts.Variables["FileNameFound"].Value.ToString())+ ".csv";

    // Get password from SSIS variable
    string encryptionKey = Dts.Variables["EncryptionKey"].ToString();

    // Create an encrypted copy of the file
    Encrypt(filepath, newFilepath, encryptionKey);

    // Close Script Task
    Dts.TaskResult = (int)ScriptResults.Success;
}

我错过了什么?

最佳答案

我成功了。我将 For Each 更改为仅检索文件名,然后修改我的代码:

public void Main()
{
    // Get the filepath of the file that needs to be encrypted. 
    string filepath = Dts.Variables["Unencrypted_Folder"].Value.ToString() + Dts.Variables["FileNameFound"].Value.ToString();

    // build output path
    string newFilepath = Dts.Variables["$Project::CSV_OutputFolder"].Value.ToString() + Dts.Variables["FileNameFound"].Value.ToString();

    // Get password from SSIS variable
    string encryptionKey = Dts.Variables["EncryptionKey"].ToString();

    // Create an encrypted copy of the file
    Encrypt(filepath, newFilepath, encryptionKey);

    // Close Script Task
    Dts.TaskResult = (int)ScriptResults.Success;
}

关于c# - SSIS 包脚本任务输出文件到新文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60114966/

相关文章:

c# - 如何使用 linq 对嵌套集合进行排序?

SQL Server 2008 - 使用 ROW_NUMBER 查找重复项

SSIS SQL 任务 - "Parameter name is unrecognized"

sql-server - 使用SSIS包导入数据后如何移动文本文件?

c# - 短路 Linq for (Count > 1)

c# - 当线程使用调度程序并且主线程正在等待线程完成时出现死锁

mysql - SQL根据列之间交换的两个键查找重复记录

sql-server - 关键字 'case' 附近的语法不正确

作业执行期间 SSIS 错误

c# - 在 Metro Windows 8 中将 ImageSource 转换为 WriteableBitmap