Solved

C# and Internet Explorer Automation

Posted on 2013-05-29
4
1,103 Views
Last Modified: 2013-06-06
I have a web page that I am loading into Internet Explorer.  I am then trying to do a “Save As” to HTML via Automation.  I have been searching for a couple days and I can’t figure out how to do this.

I have been trying to do this with Microsoft.mshtml and SHDocVw in Visual Studio.
Any direction would be greatly appreciated.
0
Comment
Question by:rye004
  • 3
4 Comments
 
LVL 16

Expert Comment

by:Kalpesh Chhatrala
Comment Utility
you can try WebClient.

WebClient MyClient = new WebClient();
Byte[] MypageData = MyClient.DownloadData("http://kalpesh.biz");
string cDoc = Encoding.ASCII.GetString(MypageData);

Open in new window


or

you can try browser automation like below
 
webBrowser1.Navigate("https://www.google.com/");

            while (true)
            {
                if (webBrowser1.ReadyState == WebBrowserReadyState.Complete)
                {
                    break;
                }
                Application.DoEvents();
            }
            String cDoc = webBrowser1.Document.Body.InnerHtml;

Open in new window



you can save cDoc in html File.
0
 

Author Comment

by:rye004
Comment Utility
Thank you kalpesh2804 for your response.
I did originally try “webBrowser1.Document.Body.InnerHtml”.
However it only gets the HTML from when the page was loaded.
With the “Save As” in IE it does a conversion process to save the HTML – which is what I am looking for.  If you take a website like “yahoo.com”, more content is added the more you scroll down.  If you do “InnerHtml”, it only gets the HTML that was loaded with the page.  However if you do a “Save As”, it does a conversion to view it later.
Hopefully this make sense.
0
 

Accepted Solution

by:
rye004 earned 0 total points
Comment Utility
So If figured out, there is not good way to do this.  What I need up doing is calling the following:

WebBrowser. ShowSaveAsDialog();

Once the dialog shows, I do the following:
            SendKeys.Send("%t{DOWN}{DOWN}~");
           
            SendKeys.Send("%s");

I realize this is lame, but it works.
0
 

Author Closing Comment

by:rye004
Comment Utility
No better reason was given.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now