如何使用Windows Phone 8中的启动器打开文档和图像

时间:2014-07-31 06:31:20

标签: c# windows-phone-8 app-launcher

我正在创建Windows Phone 8应用程序,我必须使用代码或启动器打开文档和图像。问题是那些文件没有打开那些不是在MS Office中创建的,我收到的错误如下:

"Document has been damaged, cant open" and
"File Format doesn't recognized"

我的代码在这里:

string file = "Test.xls";
var filerun = await ApplicationData.Current.LocalFolder.CreateFileAsync(file);

await Launcher.LaunchFileAsync(await ApplicationData.Current.LocalFolder.GetFileAsync(file));

1 个答案:

答案 0 :(得分:0)

试试此代码

string uriToLaunch = @"http://www.contoso.com/SomeFile.docx";
var uri = new Uri(uriToLaunch);

async void DefaultLaunch()
{
    // Set the URI’s content type
    var options = new Windows.System.LauncherOptions();
    options.ContentType = "application/vnd.ms-word.document.12";

    // Launch the URI with the content type
    var success = await Windows.System.Launcher.LaunchUriAsync(uri, options);

    if (success)
    {
        // URI launched
    }
    else
    {
        // URI launch failed
    }
}

搜索文件的正确MIME类型。