VCF Vcard导入c#

发布于 2024-12-07 06:57:08 字数 1726 浏览 0 评论 0原文

我正在尝试编写一个导入 *.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

羁客 2024-12-14 06:57:08

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

Pretty old, but it still works: https://github.com/drlongnecker/Thought.vCards

念﹏祤嫣 2024-12-14 06:57:08

您可以尝试使用此示例

You can try to use this sample.

拥醉 2024-12-14 06:57:08

海尔,抱歉耽误了这么久。

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

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”或其他参数的方法。

浆果

Helle, sry for the long delay.

I solved my problem now with the follwing code:

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);
    }
   }
 }

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

↙温凉少女 2024-12-14 06:57:08

Outlook 应用程序的解决方案并不有效。

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

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

the solution with the outlook application is not effictive.

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

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.

挖鼻大婶 2024-12-14 06:57:08

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

  1. 使用 Microsot.office.interop.outlook
    噢,不。它会先打开 Outlook,然后按照步骤您就可以完成工作了。当然这不是最好的解决方案。

  2. 使用Thought vcard。它还不错,但想象一下您有多个 vcf,并且您将它们合并到一个 vcf 中。使用此软件包太难(或几乎不可能)使用它。

  3. 使用VCardlib。它没有以前的问题,但它没有更新工作到目前为止,一直使用 vcf 版本 4。

  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:

  1. 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.

  2. 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.

  3. Use VCardlib .it doesnt has previous problem but its not update for work with vcf version4 until now.

  4. I use MixERP.NET.VCard and its more simple and effective.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文