C# Type GetTypeFromProgID(String, String)
Description
Type GetTypeFromProgID(String, String)
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.
Syntax
Type.GetTypeFromProgID(String, String)
has the following syntax.
public static Type GetTypeFromProgID(
string progID,
string server
)
Parameters
Type.GetTypeFromProgID(String, String)
has the following parameters.
progID
- The progID of the type to get.server
- The server from which to load the type. If the server name is null, this method automatically reverts to the local machine.
Returns
Type.GetTypeFromProgID(String, String)
method returns 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,
null.
Example
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.
using System;//w w w . j ava 2s . com
class MainApp
{
public static void Main()
{
try
{
string theProgramID ="DirControl.DirList.1";
string theServer="localhost";
Type myType =Type.GetTypeFromProgID(theProgramID,theServer);
if(myType==null)
{
throw new Exception("Invalid ProgID or Server.");
}
Console.WriteLine(myType.GUID);
}
catch(Exception e)
{
Console.WriteLine("An exception occurred.");
Console.WriteLine("Source: {0}" , e.Source);
Console.WriteLine("Message: {0}" , e.Message);
}
}
}
The code above generates the following result.