title: Find certificate location on box/server
body: <p>I am trying to find where the certificate is stored on my local machine and then as well as our dev servers.  I can go Run -> MMC -> File - > Add/Remove SnapIns and select certificates and Current User and see my personal certificates.  However, I am trying to utilize this code for an HttpWebRequest and I cannot find the url.</p>
  
  <pre><code>string certPath = @"e:\mycertificate.cer"; //This Value
  X509Certificate myCert = X509Certificate.CreateFromCertFile(certPath);
  request.ClientCertificates.Add(myCert);
  </code></pre>
  
  <p>In another area we set up a proxy and do it like this.</p>
  
  <pre><code>proxy.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, CertificateName);
  </code></pre>
  
  <p>So obviously a little different implementation and I am unsure as to where/how to find the location to fill in for the first example.</p>
  
  <p><em>Solution that worked for me</em></p>
  
  <pre><code>public WebRequest GetWebRequest(string address)
  {
      HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);
      X509Certificate myCert = null;
      X509Store store = new X509Store("My");
  
      store.Open(OpenFlags.ReadOnly);
  
      foreach (X509Certificate2 mCert in store.Certificates)
      {
          if (mCert.FriendlyName.Contains("certname"))
          {
              myCert = mCert;
          }
      }
  
      if (myCert != null) { request.ClientCertificates.Add(myCert); }
  
      return request;
  }
  </code></pre>