{"id":367,"date":"2014-04-24T01:57:16","date_gmt":"2014-04-23T19:57:16","guid":{"rendered":"http:\/\/markwheeler.com\/wordpress\/?p=367"},"modified":"2014-04-24T01:57:16","modified_gmt":"2014-04-23T19:57:16","slug":"ssis-upload-file-to-sharepoint-document-library-revisited","status":"publish","type":"post","link":"https:\/\/www.markwheeler.com\/?p=367","title":{"rendered":"SSIS: Upload file to Sharepoint Document Library (revisited)"},"content":{"rendered":"<p><a href=\"http:\/\/markwheeler.com\/wordpress\/?p=231\" target=\"_blank\" rel=\"noopener\">A while ago<\/a>\u00a0I showed how to upload a file to a Sharepoint Document Library using a File Task in SSIS.<\/p>\n<p>Here&#8217;s another solution&#8230;Simply\u00a0cut and paste the following into a Script Task in your SSIS package. This is the simple version as the local file,<br \/>\nSharepoint URL and service account credentials are hardcoded. You will also need to target your script task for .Net Framework 3.5<\/p>\n<p><code><br \/>\nusing System;<br \/>\nusing System.Data;<br \/>\nusing Microsoft.SqlServer.Dts.Runtime;<br \/>\nusing Microsoft.SqlServer.Dts.Tasks.ScriptTask;<br \/>\nusing System.Windows.Forms;<br \/>\nusing System.Net;<br \/>\nusing System.IO;<\/code><\/p>\n<p>namespace ST_99ff82c376eb40a2829b74f045a2f3be<\/p>\n<p>{<\/p>\n<p>[System.AddIn.AddIn(&#8220;ScriptMain&#8221;, Version = &#8220;1.0&#8221;, Publisher = &#8220;&#8221;, Description = &#8220;&#8221;)]<br \/>\npublic partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase<br \/>\n{<br \/>\npublic void Main()<br \/>\n{<br \/>\nWebClient myWebClient;<br \/>\nstring LocalFileName;<br \/>\nstring DestinationURL;<br \/>\nbool FireAgain = true;<\/p>\n<p>try<\/p>\n<p>{<\/p>\n<p>myWebClient = new WebClient();<br \/>\nLocalFileName = &#8220;F:\\SomeFolder\\SomeFile.csv&#8221;;<\/p>\n<p>\/\/ Destination file name with year and month appended ( SomeFile_04-23-2014.csv )<\/p>\n<p>DestinationURL = &#8220;https:\/\/servername\/documentlibrary\/somefile_&#8221; + DateTime.Now.ToString(&#8220;MM-dd-yyyy&#8221;) + &#8220;.csv&#8221;;<\/p>\n<p>Console.WriteLine(LocalFileName);<\/p>\n<p>myWebClient.Credentials = new NetworkCredential(&#8220;username&#8221;, &#8220;password&#8221;,&#8221;domain&#8221;);<br \/>\nmyWebClient.Credentials = CredentialCache.DefaultNetworkCredentials;<\/p>\n<p>Dts.Events.FireInformation(0, String.Empty, String.Format(&#8220;Uploading {0} to {1}&#8221;, LocalFileName, DestinationURL), String.Empty, 0, ref FireAgain);<\/p>\n<p>\/\/ upload the file<\/p>\n<p>myWebClient.UploadFile(DestinationURL,&#8221;PUT&#8221;, LocalFileName);<\/p>\n<p>}<br \/>\ncatch (Exception ex)<br \/>\n{<br \/>\n\/\/ Catch and handle error<br \/>\nDts.Events.FireError(0, String.Empty, ex.Message, String.Empty, 0);<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A while ago\u00a0I showed how to upload a file to a Sharepoint Document Library using a File Task in SSIS. Here&#8217;s another solution&#8230;Simply\u00a0cut and paste the following into a Script Task in your SSIS package. This is the simple version as the local file, Sharepoint URL and service account credentials [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[2,10,11],"tags":[99,110],"class_list":["post-367","post","type-post","status-publish","format-standard","hentry","category-computer","category-sharepoint","category-software","tag-sharepoint-2010","tag-ssis"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/posts\/367","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=367"}],"version-history":[{"count":0,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/posts\/367\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}