我有以下代码将 Base64 字符串转换为 PDF 文件,保存它然后尝试打开它:
//Converts the Base64 data to bytes
byte[] bytes = Convert.FromBase64String(Base64String);
//Stores the converted Base64 data in the application's Local Resource directory, in PDF format
StorageFolder folder = ApplicationData.Current.LocalFolder;
string fileName = file.pdf";
CreationCollisionOption options = CreationCollisionOption.FailIfExists;
var file = await folder.CreateFileAsync(fileName, options);
var fs = await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);
var outStream = fs.GetOutputStreamAt(0);
var dataWriter = new Windows.Storage.Streams.DataWriter(outStream);
dataWriter.WriteBytes(bytes);
await dataWriter.StoreAsync();
dataWriter.DetachStream();
await outStream.FlushAsync();
string pdfPath = folder.Path + "\\" + fileName;
StorageFile fileToLaunch = await StorageFile.GetFileFromPathAsync(pdfPath);
await Windows.System.Launcher.LaunchFileAsync(fileToLaunch);
当文件在 Adobe Reader 中打开时,会显示一条消息,指出该文件仍在被其他应用程序使用。如何让我的应用程序“发布”文件,以便 Adobe 可以打开它?请注意,这是一个 Windows 8 应用程序。