May 21, 2018 at 9:01 am
I want to pass variable name User::FileDestinationPath instead hardcode folder \\[servername]\EventLog\ in SSIS script task. Please advise.
using System.IO;
string[] filePaths = Directory.GetFiles(@"\\[servername]\EventLog\","*.csv",System.IO.SearchOption.AllDirectories);
foreach (string filePath in filePaths)
File.Delete(filePath);
May 21, 2018 at 9:09 am
saptek9 - Monday, May 21, 2018 9:01 AMI want to pass variable name User::FileDestinationPath instead hardcode folder \\[servername]\EventLog\ in SSIS script task. Please advise.
using System.IO;string[] filePaths = Directory.GetFiles(@"\\[servername]\EventLog\","*.csv",System.IO.SearchOption.AllDirectories);
foreach (string filePath in filePaths)
File.Delete(filePath);
Add the variable to the 'ReadOnlyVariables' collection of your script task and reference it in code using Dts.Variables["User::myStringVariable"].Value
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
May 21, 2018 at 9:58 am
i tried as follows: but still not working.
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
private string NETWORK_PATH;
public void Main()
{
NETWORK_PATH = (string)(Dts.Variables["User::FileDestinationPath"].Value);
string[] filePaths = Directory.GetFiles(@"NETWORK_PATH", "*.csv", System.IO.SearchOption.AllDirectories);
foreach (string filePath in filePaths)
File.Delete(filePath);
Dts.TaskResult = (int)ScriptResults.Success;
}
May 21, 2018 at 10:16 am
Your C# skills could do with some work! 🙂
Try this:
public void Main()
{
string networkPath = Dts.Variables["User::FileDestinationPath"].Value;
string[] filePaths = Directory.GetFiles(networkPath , "*.csv", System.IO.SearchOption.AllDirectories);
foreach (string filePath in filePaths)
File.Delete(filePath);
Dts.TaskResult = (int)ScriptResults.Success;
}
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply