Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C# and Internet Explorer Automation

Posted on 2013-05-29
4
Medium Priority
?
1,511 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

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Loops Section Overview
Suggested Courses

885 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