Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string url = (string)Dts.Variables["User::vlink"].Value;
- string path = (string)Dts.Variables["$Project::DownloadPath"].Value;
- string filenames = (string)Dts.Variables["User::vfilename"].Value;
- string docpath = path + "\" + filenames;
- if (!Directory.Exists(path))
- {
- DirectoryInfo di = Directory.CreateDirectory(path);
- }
- {
- WebClient client = new WebClient();
- Uri uri = new Uri(url);
- client.Headers.Add("Accept-Language", " en-US");
- client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
- client.Headers.Add("Accept", "text/plain");
- client.Headers["Content-Type"] = "text/plain;charset=UTF-8";
- client.Headers.Add("Accept", " text/html, application/xhtml+xml, */*");
- client.Headers.Add("UserAgent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0");
- client.Headers["Accept-Encoding"] = "application/x-gzip";
- client.Credentials = new NetworkCredential("DWH_ETL", "159zse!*P", "SCI");
- client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileComplete);
- client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(Client_DownloadProgressChanged);
- client.DownloadFileAsync(uri, docpath);
- //while (client.IsBusy)
- //{
- // System.Threading.Thread.Sleep(1000);
- //}
- //Dts.TaskResult = (int)ScriptResults.Success;
- //MessageBox.Show("Download Complete");
- }
- }
- private void Client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
- {
- Console.WriteLine(e.BytesReceived + " " + e.ProgressPercentage);
- }
- void client_DownloadFileComplete(object sender, AsyncCompletedEventArgs e)
- {
- if (e.Error != null)
- MessageBox.Show(e.Error.Message);
- else
- MessageBox.Show("Download Completed");
- }
- #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
- }
Add Comment
Please, Sign In to add comment