Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

Type.GetTypeFromProgID Method

Gets the type associated with the specified program identifier (ProgID).

Overload List

Gets the type associated with the specified program identifier (ProgID), returning null if an error is encountered while loading the Type.

[Visual Basic] Overloads Public Shared Function GetTypeFromProgID(String) As Type
[C#] public static Type GetTypeFromProgID(string);
[C++] public: static Type* GetTypeFromProgID(String*);
[JScript] public static function GetTypeFromProgID(String) : Type;

Gets the type associated with the specified program identifier (ProgID), specifying whether to throw an exception if an error occurs while loading the type.

[Visual Basic] Overloads Public Shared Function GetTypeFromProgID(String, Boolean) As Type
[C#] public static Type GetTypeFromProgID(string, bool);
[C++] public: static Type* GetTypeFromProgID(String*, bool);
[JScript] public static function GetTypeFromProgID(String, Boolean) : Type;

Gets the type associated with the specified program identifier (progID) from the specified server, returning null if an error is encountered while loading the type.

[Visual Basic] Overloads Public Shared Function GetTypeFromProgID(String, String) As Type
[C#] public static Type GetTypeFromProgID(string, string);
[C++] public: static Type* GetTypeFromProgID(String*, String*);
[JScript] public static function GetTypeFromProgID(String, String) : Type;

Gets the type associated with the specified program identifier (progID) from the specified server, specifying whether to throw an exception if an error occurs while loading the type.

[Visual Basic] Overloads Public Shared Function GetTypeFromProgID(String, String, Boolean) As Type
[C#] public static Type GetTypeFromProgID(string, string, bool);
[C++] public: static Type* GetTypeFromProgID(String*, String*, bool);
[JScript] public static function GetTypeFromProgID(String, String, Boolean) : Type;

Example

[Visual Basic, C#, C++] The following example retrieves a type by passing a ProgID and server name. The example then displays the ClassID related to the ProgID, specifying whether to throw an exception if the ProgID or the server name is invalid.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of GetTypeFromProgID. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Imports System
Class MainApp
    Public Shared Sub Main()
        Try
            ' Use Server localhost.
            Dim theServer As String = "localhost"
            ' Use  ProgID HKEY_CLASSES_ROOT\DirControl.DirList.1.
            Dim myString1 As String = "DirControl.DirList.1"
            ' Use a wrong ProgID WrongProgID.
            Dim myString2 As String = "WrongProgID"
            ' Make a call to the method to get the type information for the given ProgID.
            Dim myType1 As Type = Type.GetTypeFromProgID(myString1, theServer, True)
            Console.WriteLine("GUID for ProgID DirControl.DirList.1 is {0}.", myType1.GUID.ToString())
            ' Throw an exception because the ProgID is invalid and the throwOnError 
            ' parameter is set to True.
            Dim myType2 As Type = Type.GetTypeFromProgID(myString2, theServer, True)
        Catch e As Exception
            Console.WriteLine("An exception occurred. The ProgID is wrong.")
            Console.WriteLine("Source: {0}", e.Source.ToString())
            Console.WriteLine("Message: {0}", e.Message.ToString())
        End Try
    End Sub 'Main 
End Class 'MainApp

[C#] 

using System;
class MainApp 
{
    public static void Main()
    {
        try
        {
            // Use server localhost.
            string theServer="localhost";
            // Use  ProgID HKEY_CLASSES_ROOT\DirControl.DirList.1.
            string myString1 ="DirControl.DirList.1"; 
            // Use a wrong ProgID WrongProgID.
            string myString2 ="WrongProgID"; 
            // Make a call to the method to get the type information for the given ProgID.
            Type myType1 =Type.GetTypeFromProgID(myString1,theServer,true);
            Console.WriteLine("GUID for ProgID DirControl.DirList.1 is {0}.", myType1.GUID);
            // Throw an exception because the ProgID is invalid and the throwOnError 
            // parameter is set to True.
            Type myType2 =Type.GetTypeFromProgID(myString2, theServer, true);
        }
        catch(Exception e)
        {
            Console.WriteLine("An exception occurred. The ProgID is wrong.");
            Console.WriteLine("Source: {0}" , e.Source);
            Console.WriteLine("Message: {0}" , e.Message);
        }
    }
}

[C++] 

#using <mscorlib.dll>

using namespace System;

int main() {
   try {
      // Use server localhost.
      String* theServer=S"localhost";
      // Use  ProgID HKEY_CLASSES_ROOT\DirControl.DirList.1.
      String* myString1 =S"DirControl.DirList.1";
      // Use a wrong ProgID WrongProgID.
      String* myString2 =S"WrongProgID";
      // Make a call to the method to get the type information for the given ProgID.
      Type* myType1 =Type::GetTypeFromProgID(myString1, theServer, true);
      Console::WriteLine(S"GUID for ProgID DirControl.DirList.1 is {0}.",__box( myType1->GUID));
      // Throw an exception because the ProgID is invalid and the throwOnError
      // parameter is set to True.
      Type* myType2 =Type::GetTypeFromProgID(myString2, theServer, true);
   } catch (Exception* e) {
      Console::WriteLine(S"An exception occurred. The ProgID is wrong.");
      Console::WriteLine(S"Source: {0}" , e->Source);
      Console::WriteLine(S"Message: {0}" , e->Message);
   }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

Type Class | Type Members | System Namespace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.