I'm using SSIS and a script task in C#.
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.
I also have a Project parameter that stores an output path, this is being assigned to 'newFilepath' within the Script Task.
Using some other code I then Encrypt the csv file.
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\\new folder\\test.csv
I need newFilepath
to be the variable $Project::CSV_OutputFolder + test.csv
I am trying to incorporate GetFileNameWithoutExtension(String)
but keep receiving the error:
The name 'GetFileNameWithoutExtension' does not exist in the current context
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:
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 命名空间中的静态类。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.