I would like to download a file from a website but the specific URL does not work unless a different page is loaded.
I literally call a web browser to load a page and then call another page to download a file.
This works but I hate it...
static void Main(string[] args)
{
//Open website
Process.Start("chrome.exe", "https://www.fapiis.gov/fapiis/allfapiisdata.action");
//Wait 20 sec
System.Threading.Thread.Sleep(20000);
//DownLoad File
Process.Start("Chrome.exe", "https://www.fapiis.gov/fapiis/downloadview?type=allFapiis");
//Wait 10 sec
System.Threading.Thread.Sleep(10000);
//Close Chrome
Process[] chromeInstances = Process.GetProcessesByName("chrome");
foreach (Process p in chromeInstances)
{ p.Kill(); }
//Move file for SSIS Processing
string[] files = System.IO.Directory.GetFiles(@"C:\Users\xxxx\Downloads", "AllFapiis*");
foreach (string file in files)
{
string fname = System.IO.Path.GetFileName(file);
System.IO.File.Copy(file, @"C:\xxxxx\FAPIIS\" + fname);
System.IO.File.Delete(file);
}
}
I tried using webclient but it can never find the 2nd page. Any other way to do this without calling a browser? Another problem is I can't direct where the download goes. It automatically goes into downloads on my user account.