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
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;
}
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy