I'm new to world of C#. What I'm trying to do is move files older than N days from one folder to another folder. This to archive files continuously. When used within SSIS package, I get error saying, "Exception has been thrown by the target of an invocation.".
Details of error:
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript() " Any thoughts ?
Code:
public partial class Script Main :
Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
string rootFolderPath = @"\\A\B";
string destinationPath = @"\\A\C";
public void Main()
{
string[] files = System.IO.Directory.GetFiles(rootFolderPath); ;
foreach (string file in files)
{
if (File.Exists(file))
{
if (File.GetCreationTime(file)
< DateTime.Now.AddDays(-1))
{
File.Move(rootFolderPath, destinationPath);
}
}
}
Dts.TaskResult = (int)ScriptResults.Success;
}
#region ScriptResults declaration
/// <summary>
/// This enum provides a convenient shorthand within the scope of this class for setting the
/// result of the script.
///
/// This code was generated automatically.
/// </summary>
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion
}
}