/// <summary> /// Download an individual file /// </summary> public static void DownloadFile(string url, string localdir) { string local = localdir + @"\"; string fileName = Path.GetFileName(new Uri(url).AbsolutePath); using (var wc = new CustomWebClient()) { wc.Proxy = null; wc.Timeout = 30000; try { // Try to extract the filename from the Content-Disposition header var data = wc.DownloadData(url); if (!String.IsNullOrEmpty(wc.ResponseHeaders["Content-Disposition"])) { fileName = wc.ResponseHeaders["Content-Disposition"].Substring(wc.ResponseHeaders["Content-Disposition"].IndexOf("filename=") + 10).Replace("\"", ""); } if (!File.Exists(local + fileName)) { //wc.DownloadFile(url, local + fileName); File.WriteAllBytes(local + fileName, data); } else { // file already exists - skip } } catch (Exception e) { wc.Dispose(); } finally { wc.Dispose(); } } }
public void Dispose() { if (_httpClient != null) { _httpClient.Dispose(); } }
public void Dispose() { StopListeningForDweets(); if (_webClient != null) { _webClient.Dispose(); } }
public void Dispose() { if (_disposed) { return; } this._disposed = true; if (myWebClient != null) { myWebClient.Dispose(); } if (bWorker != null) { bWorker.Dispose(); } if (anothersmallthreadpool != null) { anothersmallthreadpool.Dispose(); } if (myFileList != null) { myFileList.Dispose(); } }
public void Dispose() { wc.Dispose(); }