//static string GetFileNameFromUrl(string url) //{ // Uri uri; // if (!Uri.TryCreate(url, UriKind.Absolute, out uri)) // uri = new Uri(url); // return System.IO.Path.GetFileName(uri.LocalPath); //} protected async override Task <object> ExecuteAsync(AsyncCodeActivityContext context) { var username = Username.Get(context); var password = Password.Get(context); var url = URL.Get(context); var filepath = LocalPath.Get(context); var overwrite = Overwrite.Get(context); var ignoresecurity = IgnoreSecurity.Get(context); filepath = Environment.ExpandEnvironmentVariables(filepath); // if(string.IsNullOrEmpty(filename)) filename = "temp." if (System.IO.File.Exists(filepath) && !overwrite) { return(42); } using (var client = new System.Net.WebClient()) { var Expect100Continue = System.Net.ServicePointManager.Expect100Continue; var SecurityProtocol = System.Net.ServicePointManager.SecurityProtocol; if (ignoresecurity) { System.Net.ServicePointManager.Expect100Continue = true; System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Ssl3; } if (!string.IsNullOrEmpty(username) || !string.IsNullOrEmpty(password)) { client.Credentials = new System.Net.NetworkCredential(username, password); } var dir = System.IO.Path.GetDirectoryName(filepath); if (!System.IO.Directory.Exists(dir)) { System.IO.Directory.CreateDirectory(dir); } await client.DownloadFileTaskAsync(new Uri(url), filepath); if (ignoresecurity) { System.Net.ServicePointManager.Expect100Continue = Expect100Continue; System.Net.ServicePointManager.SecurityProtocol = SecurityProtocol; } } return(42); }