public

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 (http://www.twitter.com/JustinAngel/status/285552040636194816)

  • Download Gist
ShowContactTaskHackAttempt.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
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);
dataWriter.WriteBytes(cardBytes);
await dataWriter.StoreAsync();
dataWriter.DetachStream();
}
 
await outputStream.FlushAsync();
}
}
 
await Launcher.LaunchFileAsync(
await ApplicationData.Current.LocalFolder.GetFileAsync(tempName));
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.