VCF Vcard导入c#
我正在尝试编写一个导入 *.vcf 文件(Vcard)的类,因为我没有找到足够的 .net 类来解决该工作。
所以我决定将 *.vcf 文件视为 *.txt 文件。我只是使用 StreamReader 逐行导入整个文件。最后我将该行保存到列表对象中。
代码:
private List<string> vcardList = new List<String>();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
using (StreamReader reader = new StreamReader(@"H:\VS.vcf"))
{
string line;
while ((line = reader.ReadLine()) != null)
{
vcardList.Add(line);
}
}
}
导入文本后,我需要编辑行,因为我需要删除所有不必要的符号。 我尝试使用 RedEx claa:
private void button1_Click(object sender, EventArgs e)
{
vcardList[0] = Regex.Replace(vcardList[0], "BEGIN:", string.Empty);
}
对于第一行效果非常好!但 *.vcf 文件非常复杂并且总是不同。
所以我的问题是:有没有更好的方法来解决这个问题?
这是 *.vcf 文件:
BEGIN:VCARD
VERSION:2.1
N;LANGUAGE=de;CHARSET=Windows-1252:Test;Mustermann;;;(geschäftlich)
FN;CHARSET=Windows-1252:Test Mustermann (geschäftlich)
ORG:Mustermann CompanyTITLE;CHARSET=Windows-1252:CEO
TEL;WORK;VOICE:0049 1111 22 769 23 - 1
TEL;CELL;VOICE:0049 2222 33 71 55 90
ADR;WORK;PREF;CHARSET=Windows-1252:;;Frobuehl 22;Gothtown;;101092;England
LABEL;WORK;PREF;CHARSET=Windows-1252;ENCODING=QUOTED-PRINTABLE:Leihb=FChl 21=0D=0A=
101092 Frobuehl
X-MS-OL-DEFAULT-POSTAL-ADDRESS:2
URL;HOME:www.Test-Mustermann.de
EMAIL;PREF;INTERNET:[email protected]
X-MS-OL-DESIGN;CHARSET=utf-8:<card
END:VCARD
我只需要名称和地址。提前致谢
iam trying to write a class which imports *.vcf files (Vcard), because i didn´t found a adequate .net class to solve that job.
So i decided to treat the *.vcf file like a *.txt file. I just import the whole file, line by line, with a StreamReader. Finally i save the line into a List object.
The Code:
private List<string> vcardList = new List<String>();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
using (StreamReader reader = new StreamReader(@"H:\VS.vcf"))
{
string line;
while ((line = reader.ReadLine()) != null)
{
vcardList.Add(line);
}
}
}
After importing the text i needed to edit the lines, because i need to remove all the unnecessary symbols.
I tried to use the RedEx claa:
private void button1_Click(object sender, EventArgs e)
{
vcardList[0] = Regex.Replace(vcardList[0], "BEGIN:", string.Empty);
}
that works very well, for the first line! but the *.vcf file is very complex and allways different.
So my question is: Is there a better way to solve that problem?
This is the *.vcf file:
BEGIN:VCARD
VERSION:2.1
N;LANGUAGE=de;CHARSET=Windows-1252:Test;Mustermann;;;(geschäftlich)
FN;CHARSET=Windows-1252:Test Mustermann (geschäftlich)
ORG:Mustermann CompanyTITLE;CHARSET=Windows-1252:CEO
TEL;WORK;VOICE:0049 1111 22 769 23 - 1
TEL;CELL;VOICE:0049 2222 33 71 55 90
ADR;WORK;PREF;CHARSET=Windows-1252:;;Frobuehl 22;Gothtown;;101092;England
LABEL;WORK;PREF;CHARSET=Windows-1252;ENCODING=QUOTED-PRINTABLE:Leihb=FChl 21=0D=0A=
101092 Frobuehl
X-MS-OL-DEFAULT-POSTAL-ADDRESS:2
URL;HOME:www.Test-Mustermann.de
EMAIL;PREF;INTERNET:[email protected]
X-MS-OL-DESIGN;CHARSET=utf-8:<card
END:VCARD
I only need the name and address. Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
很老了,但它仍然有效:https://github.com/drlongnecker/Thought.vCards
Pretty old, but it still works: https://github.com/drlongnecker/Thought.vCards
您可以尝试使用此示例。
You can try to use this sample.
海尔,抱歉耽误了这么久。
我现在用以下代码解决了我的问题:
这只是如何使用 C# 轻松导入 VCF 文件的示例。我希望这有帮助。当然,我不会以这种方式实现它,我宁愿创建一个带有参数“incomingFile”或其他参数的方法。
浆果
Helle, sry for the long delay.
I solved my problem now with the follwing code:
This is just an example of how to easily import a VCF file with C# . i hope this helps. Of course i wouldnt implement it in that way, i rather would create a method with a parameter "incomingFile" or smth else.
Berry
Outlook 应用程序的解决方案并不有效。
这将首先打开前景。实际上,您只需要打开 vcard 并解析它即可从中提取您想要的信息。
the solution with the outlook application is not effictive.
this will open the outlook first. and actually you need only to open the vcard and parse it to extract the information you want from it.
C# 纯粹没有用于 vcfs 的特定方法或类。
但这些解决方案可以是一种方式。最后一个是最好的:
使用
Microsot.office.interop.outlook
。噢,不。它会先打开 Outlook,然后按照步骤您就可以完成工作了。当然这不是最好的解决方案。
使用Thought vcard。它还不错,但想象一下您有多个 vcf,并且您将它们合并到一个 vcf 中。使用此软件包太难(或几乎不可能)使用它。
使用VCardlib。它没有以前的问题,但它没有更新工作到目前为止,一直使用 vcf 版本 4。
我使用 MixERP.NET.VCard ,它更简单,有效。
C# purely does not has specific method or class for work with vcfs.
But these solutions can be way.last one is the best:
Work with
Microsot.office.interop.outlook
.Ohhh nooo.it will open outlook first and then after steps you can do your work.surely its not best solution.
Use Thought vcard.its not too bad but image that you have multiple vcfs and you merge them in one vcf.with this package its too hard(or almost impossible) to work with it.
Use VCardlib .it doesnt has previous problem but its not update for work with vcf version4 until now.
I use MixERP.NET.VCard and its more simple and effective.