Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Using SSIS to move some files and then delete them Expand / Collapse
Author
Message
Posted Thursday, July 18, 2013 6:34 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, December 11, 2014 11:23 AM
Points: 337, Visits: 598
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
}
}
Post #1475000
Posted Thursday, July 18, 2013 6:41 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 11:28 AM
Points: 13,641, Visits: 11,517
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 LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1475006
Posted Thursday, July 18, 2013 7:11 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, December 11, 2014 11:23 AM
Points: 337, Visits: 598
[b]
ps: wrong forum by the way


Opps.. sorry.
Post #1475024
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse