Using SSIS to move some files and then delete them

  • I am trying to use SSIS 2008 R2 to move some files and then delete them from the source.

    I created a script task to get the list of file names, modifying some code I found on the internet, but it will not compile.

    I get the following errors:

    Error1The type or namespace name 'SSISScriptTaskEntryPointAttributeAttribute' does not exist in the namespace 'Microsoft.SqlServer.Dts.Tasks.ScriptTask' (are you missing an assembly reference?)C:\Users\Potterd\AppData\Local\Temp\49\SSIS\fa887f142f8340d3bd98ccb513dd0024\ScriptMain.cs1443st_1d747df439f54db2a433b54c4e1c0786

    Error2The type or namespace name 'SSISScriptTaskEntryPointAttribute' does not exist in the namespace 'Microsoft.SqlServer.Dts.Tasks.ScriptTask' (are you missing an assembly reference?)C:\Users\Potterd\AppData\Local\Temp\49\SSIS\fa887f142f8340d3bd98ccb513dd0024\ScriptMain.cs1443st_1d747df439f54db2a433b54c4e1c0786

    Generated from the following code:

    #region Help: Introduction to the script task

    /* The Script Task search files in the specified location and within child directories of the specified location */

    #endregion

    #region Namespaces

    using System;

    using System.Data;

    using Microsoft.SqlServer.Dts.Runtime;

    using System.Windows.Forms;

    using System.IO; // Import for Directory class

    using System.Collections; // Import for ArrayList class

    #endregion

    namespace ST_e10d8186ebb34debbc31bb734b0e29a5

    {

    [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]

    public partial class ScriptMain :

    Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase

    {

    private string NETWORK_PATH;

    private string FILE_PATTREN;

    private bool isCheckForNewer = true;

    int fileAgeLimit;

    private ArrayList listForEnumerator = new ArrayList();

    private void GetFilesInFolder(string folderPath)

    {

    string[] AllFiles;

    DateTime fileChangeDate;

    TimeSpan fileAge;

    int fileAgeInDays;

    try

    {

    AllFiles = Directory.GetFiles(folderPath, FILE_PATTREN);

    foreach (string fileName in AllFiles)

    {

    fileChangeDate = File.GetLastWriteTime(fileName);

    fileAge = DateTime.Now.Subtract(fileChangeDate);

    fileAgeInDays = fileAge.Days;

    CheckAgeOfFile(fileName, fileAgeInDays);

    }

    if (Directory.GetDirectories(folderPath).Length > 0)

    {

    foreach (string childFolder in Directory.GetDirectories(folderPath))

    {

    GetFilesInFolder(childFolder);

    }

    }

    }

    catch (Exception e)

    {

    System.Windows.Forms.MessageBox.Show("Exception caught: " + e.ToString(), "Results",

    MessageBoxButtons.OK, MessageBoxIcon.Error);

    }

    }

    private void CheckAgeOfFile(string fileName, int fileAgeInDays)

    {

    if (isCheckForNewer)

    {

    if (fileAgeInDays <= fileAgeLimit)

    {

    listForEnumerator.Add(fileName);

    }

    }

    else

    {

    if (fileAgeInDays > fileAgeLimit)

    {

    listForEnumerator.Add(fileName);

    }

    }

    }

    public void Main()

    {

    // Initializing class variables with package variables

    fileAgeLimit = (int)(Dts.Variables["User::varFileAgeLimit"].Value);

    NETWORK_PATH = (string)(Dts.Variables["User::varNetworkPath"].Value);

    FILE_PATTREN = (string)(Dts.Variables["User::varFilePattern"].Value); ;

    if (fileAgeLimit < 0)

    {

    isCheckForNewer = false;

    }

    fileAgeLimit = Math.Abs(fileAgeLimit);

    GetFilesInFolder(NETWORK_PATH);

    // Return the list of files to the variable

    // for later use by the Foreach from Variable enumerator.

    Dts.Variables["User::varFileList"].Value = listForEnumerator;

    Dts.TaskResult = (int)ScriptResults.Success;

    }

    #region ScriptResults declaration

    enum ScriptResults

    {

    Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,

    Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure

    };

    #endregion

    }

    }

  • How much of the code did you copy paste? You only need to copy what's inside the main function.

    All the rest is generated by SSIS and you better not tamper with it.

    ps: wrong forum by the way 😉

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • ps: wrong forum by the way 😉

    Opps.. sorry.

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

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