public static void DownloadArticle(Paper paper, string fileSavePath, CookieContainer cookie) { if (!Directory.Exists(fileSavePath)) Directory.CreateDirectory(fileSavePath); var filepath = Path.Combine(fileSavePath,paper.GetFileName()); if (File.Exists(filepath)) File.Delete(filepath); var downloadLink = $"{ArticlesUrl}downloadpdf.ashx?id={paper.Id}&save=1"; using (var client = new ExtendedWebClient { CookieContainer = cookie }) client.DownloadFile(downloadLink, filepath); }
public static CookieContainer GetSessionCookie(string user, SecureString loginPassword) { using (var client = new ExtendedWebClient()) { var response = client.Post(LoginUrl, new Dictionary<string, string> { // Dictionary is subject of change {"__VIEWSTATE", ""}, {"ctl11$UC_LoginUser$TB_Email", user}, {"ctl11$UC_LoginUser$TB_Password", ConvertToUnsecureString(loginPassword)}, {"ctl11$UC_LoginUser$BT_Login", "Login"} }); if (!response.Contains("Logout")) throw new Exception("Login failed"); return client.CookieContainer; } }