-
May 2nd, 2010, 11:42 PM
#1
automate File Download Dialog Box in Internet Explorer?
I have searched this forum and others for my current dilemma, but to no avail. There have been several related posts but I haven't seen any solutions!
1. I am downloading zip files from a password protected website using Internet Explorer Automation. I am able to navigate to the site, login, and get to the stage where the file download dialog box pops up, but I am uncertain how to click "Open" (or "Save" and then choose a name and location). I am unable to use URLDownloadToFile due to the way the website is set up.
2. As a quick workaround, SendKeys doesnt works. . This is a bit of a hassle because I'd like to loop and download many files .
Any thoughts? Should I just assume that a programmatic solution doesn't exist? Im using now the visual studio 2008.
Cheers for your help!
-
May 3rd, 2010, 03:48 PM
#2
Re: automate File Download Dialog Box in Internet Explorer?
just use the WebClient class to download the file itself.
===============================
My Blog
-
May 4th, 2010, 02:27 AM
#3
Re: automate File Download Dialog Box in Internet Explorer?
thank you sir,
i ve tried like this
Code:
static void Main(string[] args)
{WebClient wc = new WebClient();
WebProxy wp = new WebProxy();
wp.UseDefaultCredentials = true;
wc.Proxy = wp;
wc.Credentials = new NetworkCredential("xxxxx", "yyyyyy");
string hostUri="http://www.codeguru.com/";
string uriSuffix = "http://www.codeguru.com/csharp/.net/net_asp/article.php/c17151/Images-on-the-Fly-in-ASPNET.htm";
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
// Set the BaseAddress of the Web Resource in the WebClient.
myWebClient.BaseAddress = hostUri;
Console.WriteLine("Downloading from " + hostUri + "/" + uriSuffix);
Console.WriteLine("\nPress Enter key to continue");
Console.ReadLine();
// Download the target Web Resource into a byte array.
byte[] myDatabuffer = myWebClient.DownloadData (uriSuffix);
// Display the downloaded data.
string download = Encoding.ASCII.GetString(myDatabuffer);
Console.WriteLine(download);
Console.WriteLine("Download of " + myWebClient.BaseAddress.ToString() + uriSuffix + " was successful.");
}
but it throws a "WebException
(407)Proxy authentication required."
dnt know what to do.
i ve used web browser control before to login to the site, but when i use web client control i cant even login. can i use webbrowser and webclient control together?
like to say,
login using web browser and to click the button there
to download using webclient
do reply sir..
i ve already searched in google regarding this but i cant find the necessary things..
thanks.
nisha khan
-
February 28th, 2011, 04:54 AM
#4
Re: automate File Download Dialog Box in Internet Explorer?
I found a way to do this with Internet Explorer 6 in Windows XP SP3.
(Sorry, VBA code)
'ButtonHwnd is the pointer to the Save button
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Integer, ByVal Y As Integer) As Long
Private Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Const MOUSEEVENTF_LEFTDOWN As Long = &H2
Private Const MOUSEEVENTF_LEFTUP As Long = &H4
Dim pos As RECT
' We get the button position
GetWindowRect ButtonHwnd, pos
' We simulate an entering of the cursor in the button. IE think this is a human :-).
' We need three steps: out, entering and in.
' Out
SetCursorPos (pos.Left - 10), (pos.Top - 10)
Sleep 100
' Entering
SetCursorPos pos.Left, pos.Top
Sleep 100
' In
SetCursorPos (pos.Left + pos.Right) / 2, (pos.Top + pos.Bottom) / 2
' We do clic with the left button. You can use SendInput instead
' With 400 miliseconds it works.
mouse_event MOUSEEVENTF_LEFTDOWN, (pos.Left + pos.Right) / 2, (pos.Top + pos.Bottom) / 2, 0, 0
Sleep 400
mouse_event MOUSEEVENTF_LEFTUP, (pos.Left + pos.Right) / 2, (pos.Top + pos.Bottom) / 2, 0, 0
Please, tell if it works for you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|