Title: .NET Compact Framework: GMail Contacts Importer
Slug: net-compact-framework-gmail-contacts-importer
Date: 2007-08-25 04:10:00
Author: Kartones
Lang: en
Tags: Mobile Dev, CSV, .NET, C#
Description: A review of the .NET Compact Framework: GMail Contacts Importer tool that I built.

 <p>Yesterday I finished toying with PocketOutlook and GMail CSV export option. Now I've got (at last) my GMail contacts clean and tidy, and imported into my phone.</p> <p>I did a small application that reads a CSV file (you must export your contact list in 'GMail CSV' format) and imports it using the PocketOutlook .NET object model. I can only say it's great, I spent more time mapping GMail fields into Outlook fields that coding business logic (and the whole coding didn't took me more than a few hours).</p> <p>This is how the app looks:</p> <p><img src="https://images.kartones.net/posts/screenshots/gmail_contacts_importer_pocketpc.jpg" mce_src="https://images.kartones.net/posts/screenshots/gmail_contacts_importer_pocketpc.jpg"> </p> <p>As for the source code, it is for Windows Mobile 6, and uses the fantastic <a href="http://filehelpers.sourceforge.net/">FileHelpers Library</a> (thanks for showing it to me, <a href="http://blogs.clearscreen.com/dtax/">Jesus</a>). The main PPC app just instantiates my <font face="Courier New">GMail2PocketOutlookLib</font> which does all the heavy stuff.</p> <p>To access Outlook just reference <font face="Courier New">Microsoft.WindowsMobile.PocketOutlook</font> and write code like this:</p> <p><font face="Courier New"><font color="black">OutlookSession outlookSession </font><font color="blue">= new </font><font color="black">OutlookSession()</font></font><font face="Courier New"><font color="blue">;<br><br></font><font color="black">ContactCollection existingContacts </font><font color="blue">= </font><font color="black">outlookSession.Contacts.Items</font></font><font face="Courier New"><font color="blue">;<br><br></font><font color="black">Contact newContact </font><font color="blue">= new </font><font color="black">Contact()</font></font><font face="Courier New"><font color="blue">;<br><br></font><font color="black">newContact.FirstName </font><font color="blue">= </font><font color="black">newContacts[index].Name</font></font><font face="Courier New"><font color="blue">;<br></font><font color="black">newContact.FileAs </font><font color="blue">= </font><font color="black">newContacts[index].Name</font></font><font face="Courier New"><font color="blue">;<br></font><font color="black">newContact.Email1Address </font><font color="blue">= </font><font color="black">newContacts[index].Email</font></font><font color="blue" face="Courier New">;<br><br></font><font face="Courier New"><font color="darkgreen">// ...<br><br></font><font color="black">existingContacts.Add(newContact)</font><font color="blue">;</font></font></p> <p>With FileHelpers I did all the CSV reading in no time, and as you can see the import process can't be easier.</p> <p>You can download the full source code and binaries <a href="https://kartones.net/downloads/pocketpc001.zip">in the Downloads section</a>.</p> <p> </p> <p>Next is doing a bit of I+D about Google Calendar API and coding a small sync tool. I don't like the fact that either you sync with outlook or you can't sync anything except files (and I use Google Calendar instead of Outlook).</p> <p> </p> <p><b>Note</b>: Code contains one unused Property, some comments missing, and the import process may mess up because of some issues with GMail CSV contents (there's a txt file explaining all). Initially I don't plan to update it, but if you fix or improve something, you're welcome!</p>
