MailBee.NET Objects 4.0

CertificateStore.AddCertificates Method 

Adds all the certificates from the specified collection to the store.

public bool AddCertificates(
   CertificateCollection certs,
   bool overwrite
);

Parameters

certs
The collection of the certificates to be added to the store.
overwrite
Sets whether the same certificates should be overwritten if they already exist in the store.

Return Value

true if the certificates were successfully added to the store; otherwise, false.

Remarks

If this method successfully added at least one certificate from the collection and then failed while adding the next certificate, those certificates which have already been added will remain in the store. In other words, adding multiple certificates is not a single transaction.

Exceptions

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

Example

This sample creates a special store and fills it with the certificates belonging to user@domain.com entity and saves this store to disk.

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

// The actual code (put it into a method of your class).
CertificateStore newStore = new CertificateStore("", CertStoreType.Memory, null);
CertificateStore myStore = new CertificateStore(CertificateStore.Personal, CertStoreType.System, null);
CertificateCollection coll = myStore.FindCertificates("user@domain.com", CertificateFields.EmailAddress);

newStore.AddCertificates(coll, false);
newStore.SaveToFile(@"C:\Temp\store.sst", CertStoreFileType.Sst, null);
[Visual Basic]
' To use the code below, import MailBee namespace at the top of your code
Imports MailBee.Security

' The actual code (put it into a method of your class).
Dim newStore As CertificateStore = New CertificateStore("", CertStoreType.Memory, Nothing)
Dim myStore As CertificateStore = New CertificateStore(CertificateStore.Personal, CertStoreType.System, Nothing)
Dim coll As CertificateCollection = myStore.FindCertificates("user@domain.com", CertificateFields.EmailAddress)

newStore.AddCertificates(coll, False)
newStore.SaveToFile("C:\Temp\store.sst", CertStoreFileType.Sst, Nothing)

See Also

CertificateStore Class | MailBee.Security Namespace | CertificateCollection | AddCertificate