private void LoadCertificate() { var store = new X509Store(StoreName.Root, StoreLocation.LocalMachine); store.Open(OpenFlags.ReadOnly); // Set Minimum to 1 to represent the first file being copied. this.InvokeEx(f => f.pBarCert.Minimum = 1); // Set Maximum to the total number of files to copy. this.InvokeEx(f => f.pBarCert.Maximum = store.Certificates.Count); // Set the initial value of the ProgressBar. this.InvokeEx(f => f.pBarCert.Value = 1); // Set the Step property to a value of 1 to represent each file being copied. this.InvokeEx(f => f.pBarCert.Step = 1); ListaCertificati lista = ListaCertificati.Instance; foreach (X509Certificate2 x509 in store.Certificates) { this.InvokeEx(f => f.pBarCert.PerformStep()); Console.WriteLine("certificate name: {0}", x509.Subject); Console.WriteLine("Simple Name: {0}{1}", x509.GetNameInfo(X509NameType.SimpleName, true), Environment.NewLine); lista.Add(x509.GetNameInfo(X509NameType.SimpleName, true) + " - " + x509.FriendlyName); // Thread.Sleep(1); } lista.Sort(); Thread.Sleep(500); this.InvokeEx(f => f.Close()); }
private void Form1_Load(object sender, EventArgs e) { ListaCertificati lista = ListaCertificati.Instance; listBoxCert.DataSource = lista.lista; int index = listBoxCert.FindString("Firebird.local"); // Determine if a valid index is returned. Select the item if it is valid. if (index != -1) { button_add_certificate.Enabled = false; listBoxCert.SetSelected(index, true); } else { button_add_certificate.Enabled = true; } }