by
0
6
1,492
0
Top 1% !
Popular
Famous
Easy-to-find
Specified
OpenSource
Popularity: 16787th place

Published on:

LanguageCSharp
LicenseMIT_X11
OSWindows

ExportContacts: Export all contacts into the CSV file from Office 365 Exchange Online.

<summary>
Export all contacts into the CSV file from Office 365 Exchange Online.
</summary>
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/287394/ExportContacts--Export-all-contacts-into?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
using System; using System.Collections.Generic; using Microsoft.Exchange.WebServices.Data; using System.Net; using System.Net.Security; using System.Security.Cryptography.X509Certificates; using System.IO; /// <summary> /// Export all contacts into the CSV file from Office 365 Exchange Online. /// </summary> private static void ExportContacts(ExchangeService service) { // Get the properties we need to write. PropertySet propertySet = new PropertySet(); Dictionary<PropertyDefinitionBase, String> schemaList = ContactsHelper.GetSchemaList(); propertySet.AddRange(schemaList.Keys); List<Item> results = GetItems(service, null, WellKnownFolderName.Contacts, propertySet); String path = GetFolderPath(); String filePath = Path.Combine(path, "contacts.csv"); using (StreamWriter writer = new StreamWriter(filePath)) { Boolean firstCell = true; // Write the head title foreach (PropertyDefinitionBase head in schemaList.Keys) { if (!firstCell) { writer.Write(","); } else { firstCell = false; } writer.Write("\"{0}\"",schemaList[head]); } writer.WriteLine(); firstCell = true; // Write the contact. foreach (Item item in results) { Contact contact = item as Contact; foreach (PropertyDefinitionBase proerty in schemaList.Keys) { if (!firstCell) { writer.Write(","); } else { firstCell = false; } ContactsHelper.WriteContacts(writer, proerty, contact); } writer.WriteLine(); firstCell = true; } } Console.WriteLine(); Console.WriteLine("Export the contacts to the file:{0}",filePath); }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus