public void DownloadFile(string link, string filePath) { using (var wc = new CookieWebClient()) { // if (!System.IO.File.Exists(filePath)) // { wc.DownloadFile(link, filePath); //} } }
public string DownloadCall(ServerCallParameters parameters) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } using (var client = new CookieWebClient()) { if (Cookie != null) { client.Cookies.Add(new Cookie(CookieName, Cookie, "/", new Uri(Url).Host)); } string url = parameters.Api; if (parameters.Api != null && !parameters.Api.StartsWith("/")) { url = "/" + url; } var uri = new EditableUri(Url + url); if (!string.IsNullOrWhiteSpace(parameters.Format)) { uri.Parameters["f"] = parameters.Format; } if (parameters.Lcid != 0) { uri.Parameters["l"] = parameters.Lcid; } try { var filePath = LongPath.GetTempFileName(); client.DownloadFile(uri.ToString(), filePath); return(filePath); } catch (WebException e) { if (ShowMessageBoxOnError) { var eb = new ErrorBox(e, e.GetErrorText(null)); eb.ShowDialog(); } throw; } } }