Solved

C# and Internet Explorer Automation

Posted on 2013-05-29
4
1,132 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
ID: 39207685
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
ID: 39209326
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
ID: 39213645
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
ID: 39224991
No better reason was given.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

910 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

24 Experts available now in Live!

Get 1:1 Help Now