无法将项目添加到列表框...

编程入门 行业动态 更新时间:2024-10-25 09:32:57
本文介绍了无法将项目添加到列表框...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好,我正在使用代码显示列表框中所有启动项目的环境变量%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" } }

推荐答案

看到: See this: //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 ;) }

你可以使用 Directory.GetFiles()方法 [ ^ ]谢尔盖的建议。 谢谢谢尔盖;)

You can use Directory.GetFiles() method[^] too - Sergey''s suggest. Thank you, Sergey ;)

更多推荐

无法将项目添加到列表框...

本文发布于:2023-11-13 14:19:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584552.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:项目   列表

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!