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

Type.GetTypeFromProgID Method (String, String)

.NET Framework 1.1

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

Parameters

progID
The progID of the type to get.
server
The server from which to load the type. If the server name is a null reference (Nothing in Visual Basic), this method automatically reverts to the local machine.

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 prodID is a null reference (Nothing in Visual Basic).

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 and server name. The example then displays the ClassID related to the ProgID, or throws an exception if the ProgID or the server name is invalid.

[Visual Basic] 
Imports System
Class MainApp
    Public Shared Sub Main()
        Try
            ' Use ProgID localhost\HKEY_CLASSES_ROOT\DirControl.DirList.1.
            Dim theProgramID As String = "DirControl.DirList.1"
            ' Use Server name localhost.
            Dim theServer As String = "localhost"
            ' Make a call to the method to get the type information for the given ProgID.
            Dim myType As Type = Type.GetTypeFromProgID(theProgramID, theServer)
            If myType Is Nothing Then
                Throw New Exception("Invalid ProgID or server.")
            End If
            Console.WriteLine("GUID for ProgID DirControl.DirList.1 is {0}.", myType.GUID.ToString())
        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 localhost\HKEY_CLASSES_ROOT\DirControl.DirList.1.
            string theProgramID ="DirControl.DirList.1"; 
            // Use the server name localhost.
            string theServer="localhost";
            // Make a call to the method to get the type information for the given ProgID.
            Type myType =Type.GetTypeFromProgID(theProgramID,theServer);
            if(myType==null)
            {
                throw new Exception("Invalid ProgID or Server.");
            }
            Console.WriteLine("GUID for ProgID DirControl.DirList.1 is {0}.", myType.GUID);
        }
        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 localhost\HKEY_CLASSES_ROOT\DirControl::DirList.1.
      String* theProgramID =S"DirControl.DirList.1";
      // Use the server name localhost.
      String* theServer=S"localhost";
      // Make a call to the method to get the type information for the given ProgID.
      Type* myType =Type::GetTypeFromProgID(theProgramID, theServer);
      if (myType==0) {
         throw new Exception(S"Invalid ProgID or Server.");
      }
      Console::WriteLine(S"GUID for ProgID DirControl.DirList.1 is {0}.",__box( myType->GUID));
   } 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.