Windows 8 Metro应用程序访问任意文件路径 [英] Windows 8 metro application access arbitrary file path

查看:53
本文介绍了Windows 8 Metro应用程序访问任意文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Metro中,以下代码将引发异常:

In metro, the codes like following will throw exception:

String fileName = @"C:\Test\dd\ccc.jpg";
StorageFile file = await StorageFile.GetFileFromPathAsync(fileName);

但是,即使我检查了功能中的所有内容,也添加了文件选择器,并允许所有文件类型.我仍然无法访问此文件,将引发相同的异常.

However even if I check everything in capabilities, also File Picker was added and all file types allowed. I still can't access this file, the same exception will be thrown.

有人知道如何在任意文件路径中读取文件吗?在Metro风格的应用程序中有可能吗?

Does someone know how to read file in arbitrary file path? Is that possible in metro style application.

推荐答案

不可能.您可以进入库-图片,文档,视频-并且如果用户将该文件夹放入这些库之一(使用桌面端的Windows资源管理器),则一切就绪.您甚至可以编写将文件夹放入库的桌面exe,但不能自己启动该exe或确保用户没有手动更改库.

Not possible. You can get to the Libraries - pictures, documents, videos - and if the user puts that folder into one of those libraries (using Windows Explorer on the desktop side) you're all set. You can even write a desktop exe that will put the folder into the library, but you can't launch that exe yourself or be sure that the user hasn't changed the libraries by hand.

查找SHCreateItemInKnownFolder,以获取用于库工作的Shell API的起点.我没有尝试从Metro端调用这些API;您可以看到它们是否有帮助,但我敢打赌,它们将不可用.如果您不喜欢COM与Shell API互操作,则可以查看 Windows API代码包的源代码. -我不想将其与Metro应用程序捆绑在一起,但是您可以将其一部分复制到您的应用程序中.

Look up SHCreateItemInKnownFolder for a starting point to the shell APIs for library work. I haven't tried calling those APIs from the Metro side; you can see if they help but my bet is they will not be available. If you don't like the COM interop to the shell APIs you could look at the source code to the Windows API Code Pack - I wouldn't want to bundle all of it with a Metro app, but you could copy parts of it to your application.

这篇关于Windows 8 Metro应用程序访问任意文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆