I want to pass variable name User::FileDestinationPath instead hardcode folder \\[servername]\EventLog\ in SSIS script task. Please advise.

  • 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);

  • saptek9 - Monday, May 21, 2018 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);

    Add the variable to the 'ReadOnlyVariables' collection of your script task and reference it in code using Dts.Variables["User::myStringVariable"].Value

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • 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;
            }

  • 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;

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply