错误:“';文件名.docx”;已经损坏并且可以';无法打开'";在Windows Phone

本文关键字:Phone Windows quot 损坏 docx 文件名 错误 | 更新日期: 2023-09-27 18:26:37

我试图打开文档,但遇到错误。我该如何解决?这让我很头疼,任何类型的文档都无法在我的应用程序中打开。我正在尝试使用"PDF阅读器"打开PDF文件,但出现了这样的错误:

"Unable to Open"

请推荐我。请参阅下面的代码。

string file = "test.docx";
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
if (isf.FileExists(file))
{
     isf.DeleteFile(file);
}
var filerun = await ApplicationData.Current.LocalFolder.CreateFileAsync(file);
StorageFolder folder = ApplicationData.Current.LocalFolder;
StorageFile fileopen = await folder.GetFileAsync(file);
await Launcher.LaunchFileAsync(fileopen);

错误:“';文件名.docx”;已经损坏并且可以';无法打开'";在Windows Phone

您似乎正在创建一个完全空的文件,然后尝试用WordPDFReader打开它。

在Windows Phone上,您无法使用Word打开一个名为filename.docx的emty文件-尝试在计算机上创建一个文本文件Files.txt,将其重命名为file.docx,复制到您的手机,然后通过文件应用程序打开-它不起作用。

文件扩展名只帮助确定文件类型,但最重要的是文件内部的内容。

例如,您应该能够打开使用Word创建的文件。以下是我如何做到这一点的示例-将docx文件(例如在使用Word的计算机上创建)添加到您的解决方案中,并将其构建操作更改为内容。然后试着这样打开它:

private async void firstBtn_Click(object sender, RoutedEventArgs e)
{
    StorageFolder folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
    StorageFile file = await folder.GetFileAsync("sample.docx");
    await Launcher.LaunchFileAsync(file);
}

正如我所尝试的,应该可以毫无问题地工作。如果你遇到一些,这里有一个工作样本。

没有什么可以阻止你准备一些空的docx模板,然后在应用程序中复制为新文件并打开它们。您还可以尝试查找API来创建Office文件。