繁体   English   中英

如何从ApplicationData.Current.LocalFolder中提取字符串路径

[英]How to extract String path from ApplicationData.Current.LocalFolder

我需要使用ApplicationData.Current.LocalFolder中保存的文件创建一个ListBox,以后可以用来打开这些文件。

我有这样的事情:

string path = ApplicationData.Current.LocalFolder;

DirectoryInfo dinfo = new DirectoryInfo(@path);    
FileInfo[] Files = dinfo.GetFiles("*.txt");

foreach (FileInfo file in Files)
{
listbox1.Items.Add(file.Name);
}

但是,即使我找到了一些将ApplicationData.Current.LocalFolder直接分配给字符串的示例代码,也出现了一个错误:“无法将Windows.Storage.StorageFoler隐式转换为字符串。”

你能告诉我怎么做吗?

谢谢

好,

我自己解决了这个问题,因此对于任何寻求答案的人,这里您都可以:

string path = ApplicationData.Current.LocalFolder.Path;

DirectoryInfo dinfo = new DirectoryInfo(@path);    
FileInfo[] Files = dinfo.GetFiles("*");

foreach (FileInfo file in Files)
{
     historia.Items.Add(file.Name);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM