X500DistinguishedName.Name Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the comma-delimited distinguished name from an X500 certificate.

Namespace:   System.Security.Cryptography.X509Certificates
Assembly:  System (in System.dll)

public string Name { get; }

Property Value

Type: System.String

The comma-delimited distinguished name of the X509 certificate.

The distinguished name uses the following format:

[X500:/C=CountryCode/O=Organization/OU=OrganizationUnit/CN=CommonName]

The following code example shows how to use the X500DistinguishedName class.

using System;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.IO;
using System.Security.Cryptography.X509Certificates;

class X500Sample
{
	static void Main()
	{
		try
		{
			X509Store store = new X509Store("MY", StoreLocation.CurrentUser);
			store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
			X509Certificate2Collection collection = (X509Certificate2Collection)store.Certificates;
			X509Certificate2Collection fcollection = (X509Certificate2Collection)collection.Find(X509FindType.FindByTimeValid, DateTime.Now, false);
			X509Certificate2Collection scollection = X509Certificate2UI.SelectFromCollection(fcollection, "Test Certificate Select", "Select a certificate from the following list to get information on that certificate", X509SelectionFlag.MultiSelection);
			Console.WriteLine("Number of certificates: {0}{1}", scollection.Count, Environment.NewLine);
			foreach (X509Certificate2 x509 in scollection)
			{
				X500DistinguishedName dname = new X500DistinguishedName(x509.SubjectName);
				Console.WriteLine("X500DistinguishedName: {0}{1}", dname.Name, Environment.NewLine);
				x509.Reset();
			}
			store.Close();
		}
		catch (CryptographicException)
		{
			Console.WriteLine("Information could not be written out for this certificate.");
		}

	}
}

.NET Framework
Available since 2.0
Return to top
Show: