Export (0) Print
Expand All

X509Certificate.CreateFromCertFile Method

Creates an X.509v3 certificate from the specified certification file.

[Visual Basic]
Public Shared Function CreateFromCertFile( _
   ByVal filename As String _
) As X509Certificate
[C#]
public static X509Certificate CreateFromCertFile(
 string filename
);
[C++]
public: static X509Certificate* CreateFromCertFile(
 String* filename
);
[JScript]
public static function CreateFromCertFile(
   filename : String
) : X509Certificate;

Parameters

filename
The path of the certification file from which to create the X.509 certificate.

Return Value

The newly created X.509 certificate.

Exceptions

Exception Type Condition
ArgumentException The file specified by the filename parameter cannot be found.

Remarks

ASN.1 DER is the only certificate format supported by this class.

Example

[Visual Basic] 
Imports System
Imports System.Security.Cryptography.X509Certificates




Public Class X509
   
   
   Public Shared Sub Main()
      
      ' The path to the certificate.
      Dim Certificate As String = "Certificate.cer"
      
      ' Load the certificate into an X509Certificate object.
      Dim cert As X509Certificate = X509Certificate.CreateFromCertFile(Certificate)
      
      ' Get the value.
      Dim resultsTrue As String = cert.ToString(True)
      
      ' Display the value to the console.
      Console.WriteLine(resultsTrue)
      
      ' Get the value.
      Dim resultsFalse As String = cert.ToString(False)
      
      ' Display the value to the console.
      Console.WriteLine(resultsFalse)
   End Sub  
End Class 


[C#] 

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


public class X509
{

    public static void Main()
    {

        // The path to the certificate.
        string Certificate =  "Certificate.cer";

        // Load the certificate into an X509Certificate object.
        X509Certificate cert = X509Certificate.CreateFromCertFile(Certificate);

        // Get the value.
        string resultsTrue = cert.ToString(true);
       
        // Display the value to the console.
        Console.WriteLine(resultsTrue);

        // Get the value.
        string resultsFalse = cert.ToString(false);
       
        // Display the value to the console.
        Console.WriteLine(resultsFalse);
  
    }

}

[C++] 

#using <mscorlib.dll>
using namespace System;
using namespace System::Security::Cryptography::X509Certificates;

int main()
{

    // The path to the certificate.
    String* Certificate =  S"Certificate.cer";

    // Load the certificate into an X509Certificate object.
    X509Certificate* cert = X509Certificate::CreateFromCertFile(Certificate);

    // Get the value.
    String* resultsTrue = cert->ToString(true);

    // Display the value to the console.
    Console::WriteLine(resultsTrue);

    // Get the value.
    String* resultsFalse = cert->ToString(false);

    // Display the value to the console.
    Console::WriteLine(resultsFalse);

}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

X509Certificate Class | X509Certificate Members | System.Security.Cryptography.X509Certificates Namespace

Show:
© 2014 Microsoft