Create a gist now

Instantly share code, notes, and snippets.

This is an attempt on Windows Phone 8 to trigger a Contact's Details UI to be displayed by creating a VCF file. This is at the suggestion of @justinangel (
private async void listBox_ItemTap(object sender, Telerik.Windows.Controls.ListBoxItemTapEventArgs e)
var result = (Contact)e.Item.AssociatedDataItem.Value;
var test = new ContactInformation();
test.GivenName = result.CompleteName.FirstName;
test.FamilyName = result.CompleteName.LastName;
test.DisplayName = result.DisplayName;
var vCard = await test.ToVcardAsync();
var tempName = Guid.NewGuid().ToString() + ".vcf";
var file = await ApplicationData.Current.LocalFolder.CreateFileAsync(tempName);
using (IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.ReadWrite))
using (IOutputStream outputStream = fileStream.GetOutputStreamAt(0))
using (DataWriter dataWriter = new DataWriter(outputStream))
var vcardStream = vCard.AsStream();
var cardBytes = new byte[vcardStream.Length];
await vcardStream.ReadAsync(cardBytes, 0, (int)vcardStream.Length);
await dataWriter.StoreAsync();
await outputStream.FlushAsync();
await Launcher.LaunchFileAsync(
await ApplicationData.Current.LocalFolder.GetFileAsync(tempName));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment