 |
 |

01-19-2009, 01:20 PM
|
|
Centurion
|
|
Join Date: Mar 2008
Posts: 103
|
|
New Windows Contacts Format
|
Hi everyone 
As you know, from Windows Vista, user contacts are not stored in .wab files anymore...
However, they are stored here:
X:\Users\Your User Name\Contacts
I want to CREATE / GENERATE contacts programatically and save them here in the same format.
This format is very simple and is user readable.
For example, this sample:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<c:contact c:Version="1" xmlns:c="http://schemas.microsoft.com/Contact" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:MSP2P="http://schemas.microsoft.com/Contact/Extended/MSP2P">
<c:CreationDate>2009-01-19T20:16:08Z</c:CreationDate><c:Extended xsi:nil="true"/>
<c:ContactIDCollection><c:ContactID c:ElementID="7a122ea4-c7c5-4eb3-855e-39c97dc46a54"><c:Value>a18452d7-bc26-467d-8a5c-527d2c70ba8b</c:Value></c:ContactID></c:ContactIDCollection><c:EmailAddressCollection><c:EmailAddress c:ElementID="0e59a008-481c-4c99-b3cc-c85c89d616ff"><c:Type>SMTP</c:Type><c:Address>user@domain.com</c:Address><c:LabelCollection><c:Label>Preferred</c:Label></c:LabelCollection></c:EmailAddress><c:EmailAddress c:ElementID="280c131c-a5ad-41ca-acc2-aff9030c76a2" xsi:nil="true"/></c:EmailAddressCollection><c:NameCollection><c:Name c:ElementID="e8afd09a-9406-4e42-bad1-b4148ade040e"><c:FormattedName>user@domain.com</c:FormattedName></c:Name></c:NameCollection><c:PhotoCollection><c:Photo c:ElementID="834fd30a-de94-4558-b650-d3d8c3e1fcd9"><c:LabelCollection><c:Label>UserTile</c:Label></c:LabelCollection></c:Photo></c:PhotoCollection></c:contact>
So, when I want to generate and save a contact here, I simply just change the email address and re-generate random IDs and save it as a .contact file in this location:
Code:
Dim OutputString As String = Nothing
OutputString = "<?xml version=""1.0"" encoding=""UTF-8""?>" + vbNewLine
OutputString = OutputString + "<c:contact c:Version=""1"" xmlns:c=""http://schemas.microsoft.com/Contact"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:MSP2P=""http://schemas.microsoft.com/Contact/Extended/MSP2P"">" + vbNewLine
OutputString = OutputString + vbTab + "<c:CreationDate>" + Now.ToString("yyyy-MM-dd") + "T" + Now.ToString("HH:mm:ss") + "Z</c:CreationDate><c:Extended xsi:nil=""true""/>" + vbNewLine
OutputString = OutputString + vbTab + "<c:ContactIDCollection><c:ContactID c:ElementID=""" + GenerateContactID() + """><c:Value>" + GenerateContactID() + "</c:Value></c:ContactID></c:ContactIDCollection><c:EmailAddressCollection><c:EmailAddress c:ElementID=""" + GenerateContactID() + """><c:Type>SMTP</c:Type><c:Address>" + MyReaders("Email").ToString + "</c:Address><c:LabelCollection><c:Label>Preferred</c:Label></c:LabelCollection></c:EmailAddress><c:EmailAddress c:ElementID=""" + GenerateContactID() + """ xsi:nil=""true""/></c:EmailAddressCollection><c:NameCollection><c:Name c:ElementID=""" + GenerateContactID() + """><c:FormattedName>" + MyReaders("Email").ToString + "</c:FormattedName></c:Name></c:NameCollection><c:PhotoCollection><c:Photo c:ElementID=""" + GenerateContactID() + """><c:LabelCollection><c:Label>UserTile</c:Label></c:LabelCollection></c:Photo></c:PhotoCollection></c:contact>" + vbNewLine
My.Computer.FileSystem.WriteAllText(WABPath + "\" + MyReaders("Email").ToString + ".contact", OutputString, False)
However, although the final file contents will be exactly in the same format, but Windows will not recognize my created files as contacts!!!
This is strange, I am sure they are in the same format!!!
Anyone knows why this happens?!
Thank you...
|
|

01-19-2009, 01:35 PM
|
 |
Fabulous Florist
Forum Leader * Guru *
|
|
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,416
|
|
You've got two choices.
- Use a hex viewer/editor or a binary compare utility to perform a binary comparison of a working, good contacts file to the contacts file you are producing. If they are indeed identical, there is some witchcraft involved and option 2 is your best bet. If you find a difference, fix it, and make it work, be prepared to do a full review and retest every time MS releases a hotfix, service pack, or update in case they change their internal format.
- Use the Windows Address Book API which has already been suggested. This is the intended API for you to interact with these files and will always be compatible with the versions of Windows that it supports no matter how they change the file format.
I'm very partial to option 2, but option 1 "works".
|
|

01-20-2009, 06:01 AM
|
|
Centurion
|
|
Join Date: Mar 2008
Posts: 103
|
|
Hi,
I was sure I am writing the output file in the correct format, and I was right.
I cannot use the 2nd option because that's for .WAB files, and from Vista, Microsoft discontinued using .WAB formats.
However, I found the only problem is with my random generated IDs.
It seems that I really cannot generate random alphanumeric IDs on the fly and use it in the .contact files.
But how can I find how they generate these random IDs? 
|
|

01-20-2009, 06:33 AM
|
 |
Trust me, I'm an
* Expert *
|
|
Join Date: Apr 2001
Location: In ur base, pwnin d00dz
Posts: 1,961
|
|
The answer to what you want is here: http://www.codeplex.com/Contacts
An open-source managed contact API that works with Vista. It's the first hit searching google for "windows vista contacts api .net".
|
__________________
To err is human; to debug, divine.
|

01-20-2009, 08:49 AM
|
 |
Fabulous Florist
Forum Leader * Guru *
|
|
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,416
|
|
Quote:
Originally Posted by SIMIN
I cannot use the 2nd option because that's for .WAB files, and from Vista, Microsoft discontinued using .WAB formats.
|
Had you even read the first sentence of the linked documentation, you'd have read this note:
Quote:
|
Note In Windows Vista, Microsoft Windows Contacts replaces Windows Address Book (WAB). For more information about this new mechanism for storing and retrieving contact information, see Windows Contacts.
|
It had a handy link to the Windows Contacts API that works in Vista. I am certain you can read, otherwise you wouldn't have responded to my post.
Regardless, darkforcesjedi linked to a managed wrapper around this API, and that is the correct way to do this.
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|