How to save contacts in the .VCF format

后端 未结 1 1157
难免孤独
难免孤独 2020-12-18 06:28

I have a class to hold data and a list of that class. Here is my code.

static void Main(string[] args)
    {
        List contacts = ne         


        
相关标签:
1条回答
  • 2020-12-18 07:12

    Just create a StringBuilder instance and write the contents of the .VCF to it.

    var contact = new GoogleContacts() { ... };
    
    var vcf = new StringBuilder();
    vcf.Append("TITLE:" + contact.Title + System.Environment.NewLine); 
    //...
    

    Afterwards you can save it to a file using the static WriteAllText(...) method of the File type.

    var filename = @"C:\mycontact.vcf";
    File.WriteAllText(filename, vcf.ToString());
    

    Just open a .vcf file with a text editor to explore its contents. Since you only require a couple of properties it should be easy to figure out.

    A small example:

    BEGIN:VCARD
    FN:Mr. John Smith
    TITLE:Developer
    ORG:Microsoft
    BDAY:1979-12-10
    VERSION:2.1
    END:VCARD
    

    If you want to include an image you have to base 64 encode it.

    0 讨论(0)
提交回复
热议问题