1

我正在尝试编写一个导入 *.vcf 文件(Vcard)的类,因为我没有找到足够的 .net 类来解决该工作。

所以我决定将 *.vcf 文件视​​为 *.txt 文件。我只是用 StreamReader 逐行导入整个文件。最后,我将该行保存到 List 对象中。

编码:

 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:Test@Test-Mustermann.de
X-MS-OL-DESIGN;CHARSET=utf-8:<card 
END:VCARD

我只需要姓名和地址。提前致谢

4

5 回答 5

4

很老了,但它仍然有效:https ://github.com/drlongnecker/Thought.vCards

于 2011-09-29T06:38:29.290 回答
1

您可以尝试使用此示例

于 2011-09-29T06:31:08.810 回答
1

嘿嘿,抱歉耽搁了这么久。

我现在用以下代码解决了我的问题:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Outlook = Microsoft.Office.Interop.Outlook;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
    public Form1()
{
InitializeComponent();
}

    private void Form1_Load(object sender, EventArgs e)
   {
        Outlook.ContactItem contact;
        Outlook.Application app = new Outlook.Application();

        contact = (Outlook.ContactItem)app.Session.OpenSharedItem(@"C:\vv.vfc");
        MessageBox.Show(contact.FirstName);
    }
   }
 }

这只是一个如何使用 C# 轻松导入 VCF 文件的示例。我希望这有帮助。当然我不会以这种方式实现它,我宁愿创建一个带有参数“incomingFile”或其他东西的方法。

浆果

于 2011-10-07T09:20:23.073 回答
0

使用 Outlook 应用程序的解决方案无效。

Outlook.Application app = new Outlook.Application();

这将首先打开前景。实际上,您只需要打开 vcard 并对其进行解析即可从中提取您想要的信息。

于 2015-04-29T09:55:17.797 回答
0

C# 纯粹没有用于使用 vcfs 的特定方法或类。但是这些解决方案可以是方式。最后一个是最好的:

  1. Microsot.office.interop.outlook. Ohhh nooo.it 将首先打开 Outlook,然后在步骤之后您可以完成您的工作。当然这不是最好的解决方案。

  2. 使用Thought vcard。它不是太糟糕,但是您有多个 vcf 并将它们合并到一个 vcf 中的图像。这个包太难(或几乎不可能)使用它。

  3. 使用VCardlib 。它没有以前的问题,但直到现在它还没有更新为使用 vcf 版本 4。

  4. 我使用MixERP.NET.VCard,它更简单有效。

于 2020-02-10T16:32:09.860 回答