/// <summary> /// Remove file name from Recent list. /// Call this function when File - Open operation failed. /// </summary> /// <param name="fullFileName">File Name</param> public void Remove(string fullFileName) { int i = 0; IEnumerator <RecentFile> myEnumerator = RecentFilesCollection.GetEnumerator(); while (myEnumerator.MoveNext()) { if (String.Equals(myEnumerator.Current.FullFileName, fullFileName, StringComparison.InvariantCultureIgnoreCase)) { RecentFilesCollection.RemoveAt(i); return; } i++; } }
/// <summary> /// Add file name to Recent list. /// Call this function when file is opened successfully. /// If file already exists in the list, it is moved to the first place. /// </summary> /// <param name="fullFileName">File Name</param> public void Add(string fullFileName) { if (String.IsNullOrWhiteSpace(fullFileName)) { return; } Remove(fullFileName); // if array has maximum length, remove last element if (RecentFilesCollection.Count == _maxNumberOfFiles) { RecentFilesCollection.RemoveAt(_maxNumberOfFiles - 1); } // add new file name to the start of array RecentFilesCollection.Insert(0, new RecentFile(fullFileName, GetDisplayName(fullFileName))); }