繁体   English   中英

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

[英]SSIS Package Script task output file to new folder

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

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

我还有一个存储输出路径的 Project 参数,它被分配给脚本任务中的“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;
}

我错过了什么?

我让它工作了。 我将 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;
}
Path.GetFileNameWithoutExtension(Dts.Variables["FileNameFound"].Value.ToString()) 

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM