Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Using SSIS to move some files and then delete them


Using SSIS to move some files and then delete them

Author
Message
dwilliscp
dwilliscp
SSC-Addicted
SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)

Group: General Forum Members
Points: 420 Visits: 767
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:

Error 1 The 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.cs 14 43 st_1d747df439f54db2a433b54c4e1c0786

Error 2 The 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.cs 14 43 st_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
}
}
Koen Verbeeck
Koen Verbeeck
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16455 Visits: 13207
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 ;-)



How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at SQLKover.

MCSA SQL Server 2012 - MCSE Business Intelligence
dwilliscp
dwilliscp
SSC-Addicted
SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)SSC-Addicted (420 reputation)

Group: General Forum Members
Points: 420 Visits: 767
[b]
ps: wrong forum by the way ;-)


Opps.. sorry.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search