MailBee.NET Objects 4.0

CertificateStore.AddCertificate Method 

Adds the specified certificate to the store.

public bool AddCertificate(
   Certificate cert,
   bool overwrite
);

Parameters

cert
The certificate that should be added.
overwrite
Sets whether the same certificate (if it already exists in the store) should be overwritten or not.

Return Value

true if certificate was successfully added to the store; otherwise, false.

Exceptions

Exception Type Condition
MailBeeInvalidArgumentException cert is a null reference (Nothing in Visual Basic).
MailBeeCertificateStoreWin32Exception Win32 returned an error on attempt to add the certificate to the store and ThrowExceptions is true.

Example

This sample registers a new certificate store, reads a certificate from a file and adds this certificate to the newly created store.

[C#]
// To use the code below, import MailBee namespace at the top of your code
using MailBee.Security;

CertificateStore.RegisterSystemStore(@"TestStore", RegistryStoreLocation.CurrentUser);
CertificateStore store = new CertificateStore(@"TestStore", CertStoreType.System, null);
Certificate cert = new Certificate(@"C:\Temp\test.cer", CertFileType.Cer, null);
store.AddCertificate(cert, true);
[Visual Basic]
' To use the code below, import MailBee namespace at the top of your code
Imports MailBee.Security

CertificateStore.RegisterSystemStore("TestStore", RegistryStoreLocation.CurrentUser)
Dim store As CertificateStore = New CertificateStore("TestStore", CertStoreType.System, Nothing)
Dim cert As Certificate = New Certificate("C:\Temp\test.cer", CertFileType.Cer, Nothing)
store.AddCertificate(cert, True)

See Also

CertificateStore Class | MailBee.Security Namespace | AddCertificates