I'm working on an App for Win8 which should include the possibility of saving contact information. The service I use offers VCard support so I decided on using them. I can succesfully download and save them, only opening them automatically doesn't work. The files are "correct", and can be opened from the explorer without any problem. Any ideas why LaunchFileAsync isn't working?
Here's a dump of the code:
private async void SaveContactSelected()
{
IRandomAccessStreamReference img = RandomAccessStreamReference.CreateFromUri(SelectedItem.Image.UriSource);
StorageFile file = await StorageFile.CreateStreamedFileFromUriAsync(SelectedItem.Title.Replace(' ', '_')+".vcf", new Uri(SelectedItem.VCardUrl), img);
var stream = await file.OpenReadAsync();
uint size = Convert.ToUInt32(stream.Size);
IBuffer buffer = await stream.ReadAsync(new Windows.Storage.Streams.Buffer(size), size, InputStreamOptions.None);
if(!stream.CanRead)
{
//TODO: Error handling
return;
}
FileSavePicker savePicker = new FileSavePicker();
savePicker.FileTypeChoices.Add("vcard", new List<string> { ".vcf" });
savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
savePicker.SuggestedFileName = SelectedItem.Title.Replace(' ', '_') + ".vcf";
StorageFile saveDestination = await savePicker.PickSaveFileAsync();
if (saveDestination != null)
{
CachedFileManager.DeferUpdates(saveDestination);
await FileIO.WriteBufferAsync(saveDestination, buffer);
FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file);
if (status == FileUpdateStatus.Complete)
{
bool succ = await Launcher.LaunchFileAsync(saveDestination, new LauncherOptions() { DisplayApplicationPicker=true });
return;
}
else
{
//TODO: Error handling
}
}
}
An here a dump of the relevant parts of the manifest:
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="MyApp.App">
<VisualElements DisplayName="MyApp.com" Logo="Assets\Images\Logo.png" SmallLogo="Assets\Images\SmallLogo.png" Description="MyApp.com Description TODO" ForegroundText="dark" BackgroundColor="#464646">
<DefaultTile ShowName="allLogos" WideLogo="Assets\Images\LogoWide.jpg" />
<SplashScreen Image="Assets\Images\SplashScreen.png" BackgroundColor="#FFFFFF" />
<InitialRotationPreference>
<Rotation Preference="landscape" />
</InitialRotationPreference>
</VisualElements>
<Extensions>
<Extension Category="windows.search" />
<Extension Category="windows.fileTypeAssociation">
<FileTypeAssociation Name="vcard">
<DisplayName>V-Card</DisplayName>
<EditFlags OpenIsSafe="true" />
<SupportedFileTypes>
<FileType ContentType="text/x-vcard">.vcf</FileType>
</SupportedFileTypes>
</FileTypeAssociation>
</Extension>
</Extensions>
</Application>
Edit: Added manifest dump for more clarity.