Name Property
Collapse the table of content
Expand the table of content

X509Store.Name Property


Gets the name of the X.509 certificate store.

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

public string Name { get; }

Property Value

Type: System.String

The name of the certificate store.

This property returns the X.509 certificate store name. This value can indicate the type of certificates stored, such as root certificates or certificates from trusted publishers.

Legacy Code Example

This section contains two examples. The first example demonstrates how you can open standard X.509 stores and list the number of certificates in each.

The second example demonstrates how you can add and remove single certificates and ranges of certificates.

Example 1

This example tries to open each standard store in each standard location on the current computer. It prints a summary that shows whether each store exists and, if so, the number of certificates it contains.

The example creates an X509Store object for each combination of standard name and standard location. It calls the Open method with the OpenFlags.OpenExistingOnly flag, which opens the physical store only if it already exists. If the physical store exists, the example uses the Name, Location, and Certificates properties to display the number of certificates in the store.

using System;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

public class Example
    static void Main()
        Console.WriteLine("\r\nExists Certs Name and Location");
        Console.WriteLine("------ ----- -------------------------");

        foreach (StoreLocation storeLocation in (StoreLocation[]) 
            foreach (StoreName storeName in (StoreName[]) 
                X509Store store = new X509Store(storeName, storeLocation);


                    Console.WriteLine("Yes    {0,4}  {1}, {2}", 
                        store.Certificates.Count, store.Name, store.Location);
                catch (CryptographicException)
                    Console.WriteLine("No           {0}, {1}", 
                        store.Name, store.Location);

/* This example produces output similar to the following:

Exists Certs Name and Location
------ ----- -------------------------
Yes       1  AddressBook, CurrentUser
Yes      25  AuthRoot, CurrentUser
Yes     136  CA, CurrentUser
Yes      55  Disallowed, CurrentUser
Yes      20  My, CurrentUser
Yes      36  Root, CurrentUser
Yes       0  TrustedPeople, CurrentUser
Yes       1  TrustedPublisher, CurrentUser

No           AddressBook, LocalMachine
Yes      25  AuthRoot, LocalMachine
Yes     131  CA, LocalMachine
Yes      55  Disallowed, LocalMachine
Yes       3  My, LocalMachine
Yes      36  Root, LocalMachine
Yes       0  TrustedPeople, LocalMachine
Yes       1  TrustedPublisher, LocalMachine


Example 2

This example opens an X.509 certificate store, adds and deletes certificates, and then closes the store. It assumes that you have three certificates to add to and remove from a local store.

[EventSource(Name = "Litware-ProductName-ComponentName")]
public sealed class LitwareComponentNameEventSource : EventSource
    [Event(1, Task = Tasks.Request, Opcode = EventOpcode.Send)]
    public void RequestStart(Guid relatedActivityId, int reqId, string url)
        WriteEventWithRelatedActivityId(1, relatedActivityId, reqId, url);


.NET Framework
Available since 2.0
Return to top
© 2015 Microsoft