// Get a dictionary of URI parameters and values. IDictionary<string, string> queryStrings = this.NavigationContext.QueryString;
当你获取到共享文件的Token后你就可以从共享存储空间通过 GetSharedFileName文件名称(包括文件在拓展名)和 CopySharedFileAsync 将共享文件拷贝到Target应用的隔离存储区
protected override async void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); IDictionary<string, string> queryStrings = this.NavigationContext.QueryString; string fileToken = queryStrings["fileToken"]; var filename = SharedStorageAccessManager.GetSharedFileName(fileToken); var file = await SharedStorageAccessManager.CopySharedFileAsync(Windows.Storage.ApplicationData.Current.LocalFolder, filename, Windows.Storage.NameCollisionOption.ReplaceExisting, fileToken); StreamResourceInfo reader = Application.GetResourceStream(new Uri(file.Path, UriKind.Relative)); StreamReader streamRead = new StreamReader(reader.Stream); string responseString = streamRead.ReadToEnd(); streamRead.Close(); streamRead.Dispose(); MessageBox.Show(responseString); }
作为一个发出共享文件的应用要做的相对简单许多使用 Windows.System.Launcher.LaunchFileAsync 即可
private async void LaunchFileButton_Click(object sender, RoutedEventArgs rea) { // Access isolated storage. StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder; // Access the bug query file. StorageFile bqfile = await local.GetFileAsync("file1.bqy"); // Launch the bug query file. Windows.System.Launcher.LaunchFileAsync(bqfile); }