[英]SSIS Package Script task output file to new folder
I'm using SSIS and a script task in C#.我在 C# 中使用 SSIS 和脚本任务。
I have a FOR EACH Loop that looks into a folder and assigns the full path and file name of each file found to a variable called FileNameFound
which in turn is then assigned to a variable called filepath
within the Script Task.我有一个 FOR EACH 循环,它查看文件夹并将找到的每个文件的完整路径和文件名分配给一个名为
FileNameFound
的变量,然后该变量又分配给脚本任务中名为filepath
的变量。
I also have a Project parameter that stores an output path, this is being assigned to 'newFilepath' within the Script Task.我还有一个存储输出路径的 Project 参数,它被分配给脚本任务中的“newFilepath”。
Using some other code I then Encrypt the csv file.然后使用其他一些代码加密 csv 文件。
Bottom line is, I need the output to go into a different folder then where it was found but retain the same filename.最重要的是,我需要将输出放入不同的文件夹中,然后在找到它的位置但保留相同的文件名。
eg例如
c:\\folder\\test.csv
c:\\folder\\test.csv
c:\\folder\\new folder\\test.csv
c:\\folder\\new folder\\test.csv
I need newFilepath
to be the variable $Project::CSV_OutputFolder + test.csv
我需要
newFilepath
作为变量$Project::CSV_OutputFolder + test.csv
I am trying to incorporate GetFileNameWithoutExtension(String)
but keep receiving the error:我正在尝试合并
GetFileNameWithoutExtension(String)
但一直收到错误:
The name 'GetFileNameWithoutExtension' does not exist in the current context
当前上下文中不存在名称“GetFileNameWithoutExtension”
This is my code:这是我的代码:
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;
}
What am I missing?我错过了什么?
I got it working.我让它工作了。 I change the For Each to just retrieve the filename only then amended my code:
我将 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.