如何在Metro Style应用中获取文件列表 [英] How to get list of files in metro style app

查看:93
本文介绍了如何在Metro Style应用中获取文件列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

>为什么Microsoft的人员在每个.net版本之后都发生了颠倒的变化?我试图用新的地铁样式" xaml做一些简单的事情,但是今天没有什么简单的事情了.例如,我需要扫描硬盘驱动器以获取文件列表.这是一个非常简单的任务,不是吗?

但是请告诉我为什么这个非常简单的代码块不起作用

>Why guys from Microsoft change all upside down after each .net edition? I have tried to do few simples things in new ''metro style'' xaml but nothing is simple today. For example I needed to scan a hard disk drive to get list of files. This is very simple task isn''t it?

But please tell me why this pretty simple chunk of code doesn''t work

using Windows.Storage;
....

async Task AllFilesIwantToGet()
       {
           StorageFolder sf = 
            await StorageFolder.GetFolderFromPathAsync(@"d:\mydocs");


           IReadOnlyList<IStorageItem> list= await sf.GetItemsAsync();



看起来GetFolderFromPathAsync()永不停止,变量sf始终为null.我试图在MSDN上找到解决方案,但没有任何帮助.
我以为是权限问题,但是当我使用以下代码时



It looks like GetFolderFromPathAsync() never stops and variable sf is null all the time. I was trying to find solution on MSDN but there is nothing that could help.
I thought it''s a permission issue but when I use the following code

var sf = await StorageFolder.GetFolderFromPathAsync(KnownFolders.MusicLibrary.Path);



尽管我已经向MusicLirary添加了功能,但它永远不会结束得太远.

很抱歉,但是经过10年的编程,我仍然感觉像是一个新手.真烦人不用说Microsoft会再次出手.



it never ends up too allthough I have added capabilities to MusicLirary.

Sorry for this but after 10 years of programming I feel still like a newbie. This is annoying. Needless to say that Microsoft shots his own foot again.

推荐答案

您不能对未知文件夹使用storagefolder.您必须使用filepicker.

检查一下,

http://msdn.microsoft.com/en-us/library/windows/apps/jj150596.aspx [ ^ ]
You cannot use storagefolder for unknown folders. You have to use filepicker.

Check this,

http://msdn.microsoft.com/en-us/library/windows/apps/jj150596.aspx[^]


有关您的更新问题...

您必须使用


如果您想要文件夹,那么

For your updated question...

you have to use


In case u want folders, then

StorageFolder musicFolder = await KnownFolders.MusicLibrary;



如果要文件列表



If you want file list

IReadOnlyList<StorageFile> fileList =
               await KnownFolders.MusicLibrary.GetFilesAsync();


这篇关于如何在Metro Style应用中获取文件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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