I've seen various solutions to saving a file using WatiN.
My current issue is similar to the others described, I need to save a PDF file, but there's a registry key that tells IE to automatically open the PDF in a new window, rather than save it.
Ideally, I could just delete that registry key and move on. However, our security policy forbids me to do that (ugh.)
I'm looking for 开发者_StackOverflow中文版a way to find a link, right-click, and save-as using a built-in WatiN mechanism, rather than using mouse_event in user32.dll.
Is this possible?
Thanks for the help!
This is a very old question but just as a reference for other I'll post a solution to it.
I think that the approach that you are thinking of is incorrect. If you do have a link to a PDF you do have the address of the PDF (even if you have to go through other pages to form the final download URL, which you can emulate with Watin anyway) if you do have the address of the PDF file then you should just download it:
At this point you should get the link href string (that should contain the file you want to download)
using (WebClient client = new WebClient())
{
string DownloadFolder = @"C:\DownloadFolder";
if (Directory.Exists(DownloadFolder))
{
string downloadURL = "https://www.somesite.com/somepath/filename.pdf"; // this should come from the href on the a link.
client.DownloadFile(downloadURL, DownloadFolder + "\\somefilenam.pdf");
}
}
精彩评论