简体   繁体   English

使用C#将Outlook联系人获取为CSV

[英]Getting Outlook contacts to CSV using C#

I am faced with a problem at work were we have a sales team which store their contacts in Outlook and dont always use the CRM, we need these contacts to help with out analytics of the sales. 我遇到一个工作上的问题,那就是我们有一个销售团队,他们将他们的联系人存储在Outlook中并且不总是使用CRM,我们需要这些联系人来帮助进行销售分析。

Now to try and avoid forcing the sales team to use the CRM or manually export their contacts I am looking at a possible way to extract their contacts from outlook programmaticly and create a CSV file which can be emailed to the head office and then added to the database using a Perl script. 现在,为了避免强迫销售团队使用CRM或手动导出他们的联系人,我正在寻找一种可能的方法,以编程方式从Outlook中提取他们的联系人,并创建一个CSV文件,该文件可以通过电子邮件发送到总部,然后添加到使用Perl脚本的数据库。

I have ideas on ways to do parts of this ie i could make the program run as a timed task to do it daily and store a small SQLLite DB file with the program to make sure that only new contacts are added to the CSVto be emailed each time. 我对执行此操作的部分方法有想法,例如,我可以使程序作为定时任务每天运行,并在程序中存储一个小的SQLLite DB文件,以确保仅将新联系人添加到CSV中,并通过电子邮件将每个联系人时间。

The problem I currently have is I am finding it hard to find decent information on how to get to the contacts using C#. 我目前遇到的问题是,我很难找到有关如何使用C#与联系人联系的体面信息。 I have seen some info based on using Microsoft.Office.Interlop.Outlook namespace but not much more than that. 我已经看到一些基于使用Microsoft.Office.Interlop.Outlook命名空间的信息,但仅此而已。

If anyone could point me to a location where someone has tried something similar so that I could see how it is done and then create my customized program. 如果有人可以将我指向一个尝试过类似操作的位置,以便我可以看到它是如何完成的,然后创建我的自定义程序。

Thank you in advance for any help 预先感谢您的任何帮助

If you want to access the Outlook data (contacts for example) you have to add a COM reference to the Microsoft Outlook XX Object library. 如果要访问Outlook数据(例如,联系人),则必须向Microsoft Outlook XX对象库添加COM引用。

Afterwards you can create an instance of the Outlook application object: 之后,您可以创建Outlook应用程序对象的实例:

Microsoft.Office.Interop.Outlook.Application outlook;
outlook = new Microsoft.Office.Interop.Outlook.Application();   

You can get a collection of contacts in the following manner: 您可以通过以下方式获取联系人集合:

Microsoft.Office.Interop.Outlook.MAPIFolder folder =
    outlook.GetNamespace("MAPI")
        .GetDefaultFolder(OlDefaultFolders.olFolderContacts);
IEnumerable<ContactItem> contacts = folder.Items.OfType<ContactItem>();

You can then query this collection using LINQ to Objects: 然后,您可以使用LINQ to Objects查询此集合:

var query = from contact in contacts
            where contact.Email1Address != null
            select contact;

Stefan Cruysbergs created an OutlookProvider component which acts as a wrapper for the Outlook application object. Stefan Cruysbergs创建了一个OutlookProvider组件,该组件充当Outlook应用程序对象的包装。 You can use LINQ to query this provider and retrieve data such as the contacts. 您可以使用LINQ查询此提供程序并检索数据,例如联系人。

He has a full explanation of it here: 他在这里对此有完整的解释:

http://www.scip.be/index.php?Page=ArticlesNET05&Lang=NL http://www.scip.be/index.php?Page=ArticlesNET05&Lang=NL

You can download his component here: 您可以在这里下载他的组件:

http://www.scip.be/index.php?Page=DownloadNETOfficeItems&Lang=NL http://www.scip.be/index.php?Page=DownloadNETOfficeItems&Lang=NL

Study his code. 学习他的代码。 It should be enough to get you started. 它应该足以让您入门。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM