Click here to Skip to main content
15,888,195 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi I have a Web crawler. Which browses through a site. Enters a field on the Input boxes and trigger button click event. that event opens up a save as dialog box. I want to save that Excel in my local location with out any manual intervention. Is there any means to click the Save button on the button

can some one help me on this?
Posted

1 solution

The problem is not correctly recognized. You really want to save a file, not to press any button, which would be a typical abuse of technology. If you need to save some data in a file without user intervention do a simple thing — forget about using any dialog box at all.

Now, a dialog box has nothing to do with file/stream I/O, it only provides a file name. Instead, you need to come up some schema with auto-generated file names.

I would suggest to a name a file by the system time. Something like that:

C#
System.DateTime time = System.DateTime.Now;
//to get the time in the Universal Sortable Form without ':',
//such as :2011-06-15T13-45-30
string time = time.ToString("s").Replace(':', '-');
string fileName = string.Format("{0}.xls", time);


It will give you a file name unique with 1-sec resolution.

See http://msdn.microsoft.com/en-us/library/az4se3k1.aspx[^].

If some file come more frequently, you can use system ticks (100-ns intervals, frequent enough for any practical purpose:

C#
System.DateTime time = System.DateTime.Now;
//format good to fit in the biggest hex number of the type long:
string fileName = string.Format("{0:X16}.xls", time.Ticks);


—SA
 
Share this answer
 
Comments
Krisko01 19-Jul-11 6:43am    
Hi SAKryukov,

Let me explain you further. We use a web site to pull certain data. after making selections in the drop down and pressing submit button. a Pop up opens up Asking if the excel has to be saved or opened or cancel.

I just save it and attach and mail to few users everyday. I dont have control over the site from which i'm getting data. I have nearly 10 similiar reports to be downloaded everyday like this and attached in mail. I thought if Web Browser would help me automate it. I dont have to repeat the same monotonous task everyday :-(. I tried Webclient method also instead of web browser control. but I dint know how to proceed further.

THanks in advance for your help..!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900