本文介绍了无法将项目添加到列表框...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我正在使用代码显示列表框中所有启动项目的环境变量%appdata%
此代码中存在一些我需要帮助的错误....
检查注释错误的代码
有没有其他解决方案,但仍然使用%appdata%?
这是代码:
Hello, I''m using a code to show all startup items in listbox with environment variable "%appdata%
There is some errors in this code that I need help with....
Check code for commented errors
Is there any other solution but still using %appdata%?
This is the code:
private void readfiles()
{
String startfolder = Environment.ExpandEnvironmentVariables("%appdata%") + "\\Microsoft\\Windows\\Start Menu\\Programs\\Startup";
foldertoread(startfolder);
}
private void foldertoread(string folderName)
{
FileInfo[] Files = folderName.GetFiles("*.txt"); // HERE is one error "Getfiles"
foreach (var file in Directory.GetFiles(folderName))
{
startupinfo.Items.Add(file.Name); // here is another error "Name"
}
}
推荐答案
//add a reference to:
using System.IO;
private void foldertoread(string folderName)
{
DirectoryInfo di = new DirectoryInfo(folderName);
string[] fi = di.GetFiles("*.txt");
//iterate through the collection of files in fi and add it to the listbox ;)
}
你可以使用 []谢尔盖的建议。
谢谢谢尔盖;)
You can use Directory.GetFiles() method[^] too - Sergey''s suggest.
Thank you, Sergey ;)
这篇关于无法将项目添加到列表框...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!