Created
December 31, 2012 16:33
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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