C# Type GetTypeFromProgID(String, String, Boolean)
Description
Type GetTypeFromProgID(String, String, Boolean)
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.
Syntax
Type.GetTypeFromProgID(String, String, Boolean)
has the following syntax.
public static Type GetTypeFromProgID(
string progID,/* w w w. j av a 2 s .c o m*/
string server,
bool throwOnError
)
Parameters
Type.GetTypeFromProgID(String, String, Boolean)
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.throwOnError
- true to throw any exception that occurs.throwOnError
- -or-throwOnError
- false to ignore any exception that occurs.
Returns
Type.GetTypeFromProgID(String, String, Boolean)
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, specifying whether to throw an exception if the ProgID or the server name is invalid.
using System;// www. j a v a 2s.co m
class MainApp
{
public static void Main()
{
try
{
string theServer="localhost";
string myString1 ="DirControl.DirList.1";
string myString2 ="WrongProgID";
Type myType1 =Type.GetTypeFromProgID(myString1,theServer,true);
Console.WriteLine(myType1.GUID);
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);
}
}
}
The code above generates the following result.