Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Type.GetTypeFromProgID Method (String, Boolean)

.NET Framework 1.1

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( _
   ByVal progID As String, _
   ByVal throwOnError As Boolean _
) As Type
[C#]
public static Type GetTypeFromProgID(
 string progID,
 bool throwOnError
);
[C++]
public: static Type* GetTypeFromProgID(
 String* progID,
 bool throwOnError
);
[JScript]
public static function GetTypeFromProgID(
   progID : String,
 throwOnError : Boolean
) : Type;

Parameters

progID
The ProgID of the type to get.
throwOnError
true to throw any exception that occurs.

-or-

false to ignore any exception that occurs.

Return Value

The type associated with the specified program identifier (ProgID), if progID is a valid entry in the registry and a type is associated with it; otherwise, a null reference (Nothing in Visual Basic).

Exceptions

Exception Type Condition
ArgumentException progID is a null reference (Nothing in Visual Basic).
COMException The spedified ProgId is not registered.

Remarks

This method is provided for COM support. Program IDs are not used in Microsoft .NET Framework because they have been superceded by the concept of namespace.

Example

[Visual Basic, C#, C++] The following example retrieves a type by passing a ProgID, specifying whether to throw an exception if the ProgID is invalid. The example then displays the ClassID related to the ProgID, along with any applicable exception message.

[Visual Basic] 
Imports System
Class MainApp
    Public Shared Sub Main()
        Try
            ' Use the ProgID HKEY_CLASSES_ROOT\DirControl.DirList.1.
            Dim myString1 As String = "DIRECT.ddPalette.3"
            ' Use a nonexistent ProgID WrongProgID.
            Dim myString2 As String = "WrongProgID"
            ' Make a call to the method to get the type information of the given ProgID.
            Dim myType1 As Type = Type.GetTypeFromProgID(myString1, 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, True)
        Catch e As Exception
            Console.WriteLine("An exception occurred.")
            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 the ProgID HKEY_CLASSES_ROOT\DirControl.DirList.1.
            string myString1 ="DIRECT.ddPalette.3"; 
            // Use a nonexistent ProgID WrongProgID.
            string myString2 ="WrongProgID"; 
            // Make a call to the method to get the type information of the given ProgID.
            Type myType1 =Type.GetTypeFromProgID(myString1,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,true);
        }
        catch(Exception e)
        {
            Console.WriteLine("An exception occurred.");
            Console.WriteLine("Source: {0}", e.Source);
            Console.WriteLine("Message: {0}", e.Message);
        }
    }
}

[C++] 
#using <mscorlib.dll>

using namespace System;

int main() {
   try {
      // Use the ProgID HKEY_CLASSES_ROOT\DirControl.DirList.1.
      String* myString1 =S"DIRECT.ddPalette.3";
      // Use a nonexistent ProgID WrongProgID.
      String* myString2 =S"WrongProgID";
      // Make a call to the method to get the type information of the given ProgID.
      Type* myType1 =Type::GetTypeFromProgID(myString1, 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, true);
   } catch (Exception* e) {
      Console::WriteLine(S"An exception occurred.");
      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.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

Type Class | Type Members | System Namespace | Type.GetTypeFromProgID Overload List | GetProgIdForType

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