Quantcast
Channel: SQLServerCentral » Data Warehousing » Analysis Services » Latest topics
Viewing all articles
Browse latest Browse all 1341

Using SSIS to move some files and then delete them

$
0
0
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_1d747df439f54db2a433b54c4e1c0786Error 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_1d747df439f54db2a433b54c4e1c0786Generated 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 Namespacesusing System;using System.Data;using Microsoft.SqlServer.Dts.Runtime;using System.Windows.Forms;using System.IO; // Import for Directory classusing System.Collections; // Import for ArrayList class#endregionnamespace 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}}

Viewing all articles
Browse latest Browse all 1341

Trending Articles