Internet explorer control

csharp Iran
  • 13 years ago

    Hi, I am trying to write a program that will control internet explorer as part of another program but I am writing this part first.  I got a sample code from online but I am missing a using directive? Here are the errors that I got when I compiled the program.

    error CS0246: The type or namespace name 'InternetExplorer' could not be found (are you missing a using directive or an assembly reference?)

    error CS0103: The name 'NSLibStatic' does not exist in the current context

    This is the code that I ran.

    using System;
    using System.Collections.Generic;
    using System.Text;


    namespace IECONNECTION
    {
        class Program
        {
            public static bool IEOpenOnURL(string sURL)
            {
                InternetExplorer oIE = (InternetExplorer)NSLibStatic.COMCreateObject
                                                                  ("InternetExplorer.Application");

                if (oIE != null)
                {
                    object oEmpty = String.Empty;
                    object oURL = sURL;
                    oIE.Visible = false;
                    oIE.Navigate2(ref oURL, ref oEmpty, ref oEmpty, ref oEmpty, ref oEmpty);
                }
                return true;
            }
            static void Main(string[] args)
            {
            }
        }
    }


  • 13 years ago

     I'm down to one error now.

    error CS0117: 'IEConnection.NSLibStatic' does not contain a definition for 'COMCreateObject'

    namespace IEConnection
    {

        class NSLibStatic
        {
            
            private static bool IEOpenOnURL(string sURL)
            {
                InternetExplorer oIE = (InternetExplorer)NSLibStatic.COMCreateObject
                                                                  ("InternetExplorer.Application");

                if (oIE != null)
                {
                    object oEmpty = String.Empty;
                    object oURL = sURL;
                    oIE.Visible = false;
                    oIE.Navigate2(ref oURL, ref oEmpty, ref oEmpty, ref oEmpty, ref oEmpty);
                }
                return true;
            }
            static void Main(string[] args)
            {
            }
        }
    }

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“It works on my machine.” - Anonymous