private void RefreshItems() { folderList.Items.Clear(); List<VirtualFolder> vfs = new List<VirtualFolder>(); int i = 0; //use this to fill in sortorder if not there foreach (var filename in Directory.GetFiles(config.InitialFolder)) { try { if (filename.ToLowerInvariant().EndsWith(".vf") || filename.ToLowerInvariant().EndsWith(".lnk")) { //add to our sorted list VirtualFolder vf = new VirtualFolder(filename); if (vf.SortName == null) { //give it a sortorder if its not there vf.SortName = i.ToString("D3"); vf.Save(); } vfs.Add(vf); i = i + 10; } //else // throw new ArgumentException("Invalid virtual folder file extension: " + filename); } catch (ArgumentException) { Logger.ReportWarning("Ignored file: " + filename); } catch (Exception e) { MessageBox.Show("Invalid file detected in the initial folder!" + e.ToString()); // TODO : alert about dodgy VFs and delete them } } vfs.Sort((a,b) => a.SortName.CompareTo(b.SortName)); //now add our items in sorted order foreach (VirtualFolder v in vfs) folderList.Items.Add(v); }