?
Solved

C# Enumerate IE

Posted on 2009-12-18
2
Medium Priority
?
383 Views
Last Modified: 2013-12-17
I'm trying to convert this VB code below to C# can someone help me? I'm trying to enumerate through IE windows find the specified URL and grab the specified elementy by id.
Private Sub CheckWindow()
        Dim ie As InternetExplorer
        Dim shellWins As New ShellWindows

        For Each ie In shellWins
            If ie.LocationURL = "http://www.google.com" Then
                MsgBox("IE Found")
                WebBrowser1.Document.GetElementById("test").GetAttribute("value")
            End If
        Next
    End Sub

Open in new window

0
Comment
Question by:disrupt
2 Comments
 
LVL 15

Accepted Solution

by:
rajeeshmca earned 2000 total points
ID: 26082884
Hi find the below c# code....

private void CheckWindow()
{
    InternetExplorer ie = default(InternetExplorer);
    ShellWindows shellWins = new ShellWindows();
   
    foreach (var ie in shellWins) {
        if (ie.LocationURL == "http://www.google.com") {
            Interaction.MsgBox("IE Found");
            WebBrowser1.Document.GetElementById("test").GetAttribute("value");
        }
    }
}

I used the link

http://www.developerfusion.com/tools/convert/vb-to-csharp/

to convert...
0
 
LVL 15

Expert Comment

by:x77
ID: 26083278
I replaced            Ie.LocationURL == "http://www.google.com"  - By StartsWith

You need include reference to c:\Windows\System32\shdocvw.dll
And                                          using SHDocVw;
public void CheckWindow()
{
    ShellWindows windows = new ShellWindows();
    foreach (SHDocVw.InternetExplorer Ie in windows)
    {
        if (Ie.LocationURL.StartsWith ( "http://www.google.com"))
        {
            MessageBox.Show("IE Found");
            webBrowser1.Document.GetElementById("test").GetAttribute("value");
        }
    }
}

Open in new window

0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Google currently has a new report that is in beta and coming soon to Webmaster Tool accounts. This Micro Tutorial will highlight new features for Google Webmaster Tools.
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.
Suggested Courses

862 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