📄 importcontactsfromvcard.cs
字号:
namespace Imps.Client.Pc
{
using Imps.Common;
using System;
using System.IO;
using System.Text;
using System.Windows.Forms;
internal class ImportContactsFromVcard : IImportContacts
{
private ImportContactType _type;
public string GetContactsXML(IWin32Window owner, string filePath)
{
StringBuilder builder = new StringBuilder();
builder.Append("<Contacts>");
using (StreamReader reader = new StreamReader(filePath, Encoding.Default, true))
{
string str;
if (!reader.ReadLine().ToUpper().Contains("BEGIN:VCARD"))
{
throw new NotSupportedException();
}
string str2 = "";
string str3 = "";
string str4 = "";
while ((str = reader.ReadLine()) != null)
{
if (str.StartsWith("TEL;CELL;VOICE:"))
{
str2 = str.Replace("TEL;CELL;VOICE:", "");
}
if (str.StartsWith("FN"))
{
string[] strArray = str.Split(new char[] { ':' });
str3 = strArray[strArray.Length - 1];
}
if (str.StartsWith("NICKNAME:"))
{
str4 = str.Replace("NICKNAME:", "");
}
}
if (str2 != "")
{
builder.Append("<Contact>");
builder.Append(string.Format("<MobileNo>{0}</MobileNo>", str2));
builder.Append(string.Format("<Name>{0}</Name>", str3));
builder.Append(string.Format("<Nickname>{0}</Nickname>", str4));
builder.Append("</Contact>");
}
}
builder.Append("</Contacts>");
return builder.ToString();
}
public string Filter
{
get
{
return "vcf files (*.vcf)|*.vcf";
}
}
public ImportContactType Type
{
get
{
return ImportContactType.VCard;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -