PBO to VCard
August 9, 2016 Leave a comment
.PBO adalah file yang berisi kontak telpon. Biasanya digunakan pada windows. Sedangkan VCard adalah file kontak telpon yang biasanya dipakai pada HP. PBO sendiri berisi sekumpulan data VCard. Maka .PBO bisa kita pisahkan menjadi VCard. Berikut codenya.
using System; using System.Collections.Generic; using System.IO; namespace pboToVcardConsole { class Program { public static void Main(string[] args) { Console.WriteLine("Hello World!"); // TODO: Implement Functionality Here Console.WriteLine("Insert .PBO input path: "); string pathPBO = Console.ReadLine(); Console.WriteLine("Output path:"); string pathoutput = Console.ReadLine(); using (StreamReader reader = new StreamReader(pathPBO)) { int counterFile = 0; string line; string writeBuffer = "BEGIN:VCARD" + Environment.NewLine; while ((line = reader.ReadLine()) != null) { Console.WriteLine(line); if((string.Equals(line,"END:VCARDBEGIN:VCARD"))||(string.Equals(line,"END:VCARD"))) { if(!(writeBuffer.Length < 1)) { writeBuffer = writeBuffer + "END:VCARD"; if(!Directory.Exists(pathoutput))//if file doesn't exist { Directory.CreateDirectory(@pathoutput); } string namaFile = string.Format("{0}\\{1}.vcf",pathoutput,counterFile); if(!File.Exists(namaFile))//if file doesn't exist { File.Create(namaFile).Close(); } TextWriter tw = new StreamWriter(@namaFile); tw.WriteLine(writeBuffer); tw.Close(); counterFile++; writeBuffer = "BEGIN:VCARD" + Environment.NewLine; } } else { writeBuffer = writeBuffer + line + Environment.NewLine; } } } } } }
Advertisements