[英]How to retrieve list of files from the local application folder which is in Xamarin.Forms project?
I have one folder "MyFolder" created in my Xamarin.Forms project and there are few files inside that folder.我在我的 Xamarin.Forms 项目中创建了一个文件夹“MyFolder”,该文件夹内的文件很少。 How can I retrieve all the files which are in that folder?
如何检索该文件夹中的所有文件?
I tried below code but it's giving exception that Folder does not exist.我尝试了下面的代码,但它给出了文件夹不存在的异常。
foreach (var file in System.IO.Directory.GetFiles("\\MyFolder"))
{
}
Even the below code is giving the same error.即使下面的代码也给出了同样的错误。
string folderPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "MyFolder");
foreach (var file in System.IO.Directory.GetFiles(folderPath))
{
}
How to retrieve list of files from the local application folder which is in Xamarin.Forms project?
如何从 Xamarin.Forms 项目中的本地应用程序文件夹中检索文件列表?
Try to traverse the resources in the assembly of the app to detect if the resource name contains 'MyFolder'.尝试遍历应用程序集中的资源,检测资源名称是否包含“MyFolder”。 You could get the resources using
GetManifestResourceNames
method.您可以使用
GetManifestResourceNames
方法获取资源。
Don't forget to set the Build Action of all the files in the folder to EmbeddedResource .不要忘记将文件夹中所有文件的Build Action设置为EmbeddedResource 。
Check the code:检查代码:
var assembly = typeof(App).GetTypeInfo().Assembly;
var list = assembly.GetManifestResourceNames();
List<string> fileList = new List<string>();
foreach (var item in list)
{
if (item.Contains("MyFolder"))
{
fileList.Add(item);
}
}
Refer to: https://stackoverflow.com/a/47185054/11083277参考: https://stackoverflow.com/a/47185054/11083277
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.