Guest User

Untitled

a guest
Mar 22nd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. string url = (string)Dts.Variables["User::vlink"].Value;
  2. string path = (string)Dts.Variables["$Project::DownloadPath"].Value;
  3. string filenames = (string)Dts.Variables["User::vfilename"].Value;
  4. string docpath = path + "\" + filenames;
  5. if (!Directory.Exists(path))
  6.  
  7. {
  8. DirectoryInfo di = Directory.CreateDirectory(path);
  9. }
  10. {
  11. WebClient client = new WebClient();
  12. Uri uri = new Uri(url);
  13.  
  14. client.Headers.Add("Accept-Language", " en-US");
  15. client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
  16. client.Headers.Add("Accept", "text/plain");
  17. client.Headers["Content-Type"] = "text/plain;charset=UTF-8";
  18. client.Headers.Add("Accept", " text/html, application/xhtml+xml, */*");
  19. client.Headers.Add("UserAgent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0");
  20. client.Headers["Accept-Encoding"] = "application/x-gzip";
  21. client.Credentials = new NetworkCredential("DWH_ETL", "159zse!*P", "SCI");
  22. client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileComplete);
  23. client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(Client_DownloadProgressChanged);
  24.  
  25. client.DownloadFileAsync(uri, docpath);
  26.  
  27.  
  28.  
  29. //while (client.IsBusy)
  30. //{
  31. // System.Threading.Thread.Sleep(1000);
  32. //}
  33.  
  34.  
  35. //Dts.TaskResult = (int)ScriptResults.Success;
  36. //MessageBox.Show("Download Complete");
  37. }
  38.  
  39. }
  40.  
  41. private void Client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
  42. {
  43. Console.WriteLine(e.BytesReceived + " " + e.ProgressPercentage);
  44.  
  45. }
  46.  
  47. void client_DownloadFileComplete(object sender, AsyncCompletedEventArgs e)
  48. {
  49. if (e.Error != null)
  50. MessageBox.Show(e.Error.Message);
  51. else
  52.  
  53. MessageBox.Show("Download Completed");
  54. }
  55.  
  56.  
  57. #region ScriptResults declaration
  58. /// <summary>
  59. /// This enum provides a convenient shorthand within the scope of this class for setting the
  60. /// result of the script.
  61. ///
  62. /// This code was generated automatically.
  63. /// </summary>
  64. enum ScriptResults
  65. {
  66. Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
  67. Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
  68. };
  69. #endregion
  70.  
  71. }
Add Comment
Please, Sign In to add comment