0

I'm trying to read a file line by line, which works perfectly but I want to seperate the results I get into subitems in the listview.

I am also searching for all .jar files in the folder so I can use those as the name (first column). The second column needs to have the "version", the third column the "author" and the fourth column the "description".

Here's one of the text files I receive from within the jar files:

name: AFK main: com.github.alesvojta.AFK.AFK version: 2.0.5 author: Ales Vojta / schneckk description: Provides AFK messages website: http://dev.bukkit.org/server-mods/afk/ commands: afk: description: Provides AFK message when player types /afk. usage: /<command> 

this is the code I have right now:

private List<string> GetInstalledPlugins() { List<string> list = new List<string>(); lvInstalledPlugins.Items.Clear(); if (!Directory.Exists(Environment.CurrentDirectory + "\\plugins")) { Directory.CreateDirectory(Environment.CurrentDirectory + "\\plugins"); DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory + "\\plugins"); FileInfo[] fileInfo = di.GetFiles("*.jar"); foreach (var info in fileInfo) { //lvInstalledPlugins.Items.Add(info.Name); list.Add(info.Name); } } else { DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory + "\\plugins"); FileInfo[] fileInfo = di.GetFiles("*.jar"); foreach (var info in fileInfo) { //lvInstalledPlugins.Items.Add(info.Name); list.Add(info.Name); } } return list; } private void test(IEnumerable<string> list) { List<ListViewItem> PluginList = new List<ListViewItem>(); var items = new string[4]; try { foreach (var ListItem in list) { Console.WriteLine(ListItem); var name = Environment.CurrentDirectory + "\\plugins\\" + ListItem; var zip = new ZipInputStream(File.OpenRead(name)); var filestream = new FileStream(name, FileMode.Open, FileAccess.Read); var zipfile = new ZipFile(filestream); ZipEntry item; while ((item = zip.GetNextEntry()) != null) { if (item.Name == "plugin.yml") { using (var s = new StreamReader(zipfile.GetInputStream(item))) { string line; while ((line = s.ReadLine()) != null) { if (line.Contains("name")) { items[0] = line; } if (line.Contains("version")) { items[1] = line; } if (line.Contains("author")) { items[2] = line; } if (line.Contains("description")) { items[3] = line; } try { var lvitem = new ListViewItem(items); lvitem.Name = items[0]; lvitem.Text = items[0]; lvitem.SubItems.Add(items[1]); lvitem.SubItems.Add(items[2]); lvitem.SubItems.Add(items[3]); PluginList.Add(lvitem); } catch (Exception) { } } lvInstalledPlugins.Items.AddRange(PluginList.ToArray()); } } } } 

This doesn't seem to work :/, any ideas? I've been working on this for the whole day and can't seem to get it to work :(.

1 Answer 1

0

Not exactly sure of your question, but going by the title, the answer to the question below may provide some assistance.

C# listView, how do I add items to columns 2, 3 and 4 etc?

Sign up to request clarification or add additional context in comments.

1 Comment

Well, the problem is that sometimes I have empty subitems and want to put "No data..." in there, but when I try that, Visual Studio tells me that the subitem is out of range or something.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.