我正在使用 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/