【问题标题】:SSIS Package Script task output file to new folderSSIS包脚本任务输出文件到新文件夹
【发布时间】:2020-02-07 14:01:46
【问题描述】:

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

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

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

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

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

例如

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

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

我正在尝试合并GetFileNameWithoutExtension(String),但一直收到错误:

当前上下文中不存在名称“GetFileNameWithoutExtension”

这是我的代码:

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;
}

我错过了什么?

【问题讨论】:

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


    【解决方案1】:

    我让它工作了。我将 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;
    }
    

    【讨论】:

      【解决方案2】:
      Path.GetFileNameWithoutExtension(Dts.Variables["FileNameFound"].Value.ToString()) 
      

      因为它是 System.IO 命名空间中的静态类。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-07-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-07-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多