我正在开发一个适用于 Win8 的应用程序,其中应该包括保存联系信息的可能性。我使用的服务提供 VCard 支持,所以我决定使用它们。我可以成功下载并保存它们,仅自动打开它们不起作用。这些文件是“正确的”,可以从资源管理器中毫无问题地打开。为什么 LaunchFileAsync 不起作用的任何想法?
这是代码的转储:
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
}
}
}
这里是清单相关部分的转储:
<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>
编辑:为更清晰添加了清单转储。