本文介绍了如何以.VCF格式保存联系人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个用于保存数据的类和该类的列表。 这是我的代码。I have a class to hold data and a list of that class.Here is my code.static void Main(string[] args) { List<GoogleContacts> contacts = new List<GoogleContacts>(); contacts.Add(new GoogleContacts { title = "A", email = "B", im = "X" }); contacts.Add(new GoogleContacts { title = "C", email = "D", im = "Y" }); contacts.Add(new GoogleContacts { title = "E", email = "F", im = "Z" }); }}public class GoogleContacts{ public string title { get; set; } public string email { get; set; } public string im { get; set; }}我想将这些数据保存在本地磁盘的.VCF文件中。I want to save those data in a .VCF file in local Disk.推荐答案只需创建一个StringBuilder实例并将.VCF的内容写入该实例。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);//...之后,您可以使用静态 WriteAllText (...)方法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());只需使用文本编辑器打开.vcf文件即可浏览其内容。由于您只需要几个属性,因此应该很容易弄清。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.一个小例子:BEGIN:VCARDFN:Mr. John SmithTITLE:DeveloperORG:MicrosoftBDAY:1979-12-10VERSION:2.1END:VCARD如果要包含图像,则必须基于64位对其进行编码。If you want to include an image you have to base 64 encode it. 这篇关于如何以.VCF格式保存联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-11 07:44