Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

<?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:

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?! :confused:

Thank you...

  • Administrators
Posted

Not entirely sure why your existing code isn't working, have you tried doing a file comparison of an existing contact file and one you are creating (http://tortoisesvn.tigris.org/TortoiseIDiff.html is a nice tool for doing this)?

 

http://www.codeplex.com/Contacts might be worth a look as it seems to havea lot of the grunt work already done.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

Hi,

I was sure I am writing the output file in the correct format, and I was right.

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? :confused:

Posted

System.Guid.NewGuid.ToString() might help you generate the value.

 

The .ToString() method has overloads to help you format correctly to match the format.

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...