FileAs

Thu, December 8, 2005, 03:03 PM under MobileAndEmbedded
About 3 months ago I switched to a PocketPC Phone Edition 2003 SE device as my main phone (shocking that it took me so long, but it did). One of the things that really pisses me off is adding new contacts on the device:
1. Create a new contact
2. Populate the contact including entering the Name field: "Name Surname"
3. OK it and go back to the Contacts list
ACTUAL RESULT:
4. You get a an item in the list that reads "Surname, Name"
$%^&££$&*ing thing!

DESIRED RESULT:
4. Get an item that displays as "Name Surname".

I thought Windows Mobile 5.0 would have fixed this (e.g. by offering the FileAs option available on Outlook on the desktop), but when I received my JasJar (thanks Mike!), I found the same pain is there. So I am trying to find how I can change this on the device (forget synching with Outlook). Someone please tell me how and put me out of my misery.

Anyway, if you can't find how to do it on the UI, next step is to do it programmatically I guess, so that is what I did (it is so easy):

1. Create a new Windows Mobile 5.0 project in VS2005. Choose the Smart Device Project/Console project type.
2. Add a project reference to Microsoft.WindowsMobile.PocketOutlook
3. Replace Main with your own:
static void Main(string[] args){
OutlookSession os = new OutlookSession();
ContactCollection cc = os.Contacts.Items;

for (int j = 0; j < cc.Count; j++){
Contact c = cc[j];

string s = c.FileAs;
int i = s.IndexOf(',');
if (i > 0){
string s1 = s.Substring(0, i);
string s2 = s.Substring(i + 2, s.Length - i - 2);
c.FileAs = s2 + " " + s1;
c.Update();
}
}

cc.Dispose();
os.Dispose();
}

If you are targeting a WM2003 device, create the appropriate project for that and instead of adding a reference to the Microsoft assembly, add a reference to InTheHand equivalents.

Naturally, you can create a fancy UI to select which ones to change etc but the above is all I wanted. I run it every time I add new contacts.