{"id":40,"date":"2011-12-14T14:43:55","date_gmt":"2011-12-14T20:43:55","guid":{"rendered":"https:\/\/www.asberry.org\/blog_tech\/?p=40"},"modified":"2011-12-15T07:27:30","modified_gmt":"2011-12-15T13:27:30","slug":"c-to-move-files-in-ssis-script-task","status":"publish","type":"post","link":"https:\/\/asberry.org\/blog_tech\/?p=40","title":{"rendered":"C# to move files in SSIS script task"},"content":{"rendered":"<p>Most of the time that I&#8217;m creating integration packages, I have a central working directory where all the action is taking place, at the end of the package execution is where I&#8217;ll archive files so that should they be needed to troubleshoot an issue I&#8217;ve got them in a handy place. \u00a0This is a script that I created for that process. \u00a0Note that lines 7 through 19 are generated by the Visual Studio Tools for Applications in SSIS when you create the script task.<\/p>\n<pre class=\"brush: csharp; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\nusing System;\r\nusing System.IO;\r\nusing System.Data;\r\nusing Microsoft.SqlServer.Dts.Runtime;\r\nusing System.Windows.Forms;\r\n\r\nnamespace ST_218640c1eafd4eb9ab909245d34e01c7.csproj\r\n{\r\n&#x5B;System.AddIn.AddIn(&quot;ScriptMain&quot;, Version = &quot;1.0&quot;, Publisher = &quot;&quot;, Description = &quot;&quot;)]\r\npublic partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase\r\n{\r\n\r\n#region VSTA generated code\r\nenum ScriptResults\r\n{\r\nSuccess = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,\r\nFailure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure\r\n};\r\n#endregion\r\n\r\npublic void Main()\r\n{\r\nstring strOriginalFileName = @&quot;C:\\TCC\\20110722-UpdateCandidate\\UpdateHireEmpStatus.csv&quot;;\r\nstring strArchivedFileName;\r\nstring strDate;\r\nDateTime dtDate = DateTime.Now;\r\n\r\nstrDate = String.Format(&quot;{0:yyyyMMdd_HH_mm_ss}&quot;, dtDate);\r\n\r\nstrArchivedFileName = @&quot;C:\\TCC\\20110722-UpdateCandidate\\Archive\\UpdateHireEmpStatus-&quot; + strDate + &quot;.csv&quot;;\r\n\r\nFile.Move(strOriginalFileName, strArchivedFileName);\r\nDts.TaskResult = (int)ScriptResults.Success;\r\n}\r\n}\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Most of the time that I&#8217;m creating integration packages, I have a central working directory where all the action is taking place, at the end of the package execution is where I&#8217;ll archive files so that should they be needed to troubleshoot an issue I&#8217;ve got them in a handy place. \u00a0This is a script [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[3,4],"tags":[],"class_list":["post-40","post","type-post","status-publish","format-standard","hentry","category-c","category-ssis","author-aron"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4bBkH-E","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/posts\/40","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=40"}],"version-history":[{"count":7,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/posts\/40\/revisions"}],"predecessor-version":[{"id":50,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/posts\/40\/revisions\/50"}],"wp:attachment":[{"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=40"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=40"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}