Skip to content

Instantly share code, notes, and snippets.

@robertmclaws
Created December 31, 2012 16:33
Show Gist options
  • Save robertmclaws/4421095 to your computer and use it in GitHub Desktop.
Save robertmclaws/4421095 to your computer and use it in GitHub Desktop.
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)
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));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment