Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1.         private void SaveRecentFile(string path)
  2.         {
  3.  
  4.             LoadRecentList();
  5.             if (!(RecentList.Contains(path)))
  6.                 RecentList.Enqueue(path);
  7.             while (RecentList.Count > RecentListNumber)
  8.             {
  9.                 RecentList.Dequeue();
  10.             }
  11.  
  12.             StreamWriter stringToWrite = new StreamWriter(System.Environment.CurrentDirectory + "\\Recent.txt");
  13.             foreach (string item in RecentList)
  14.             {
  15.                 stringToWrite.WriteLine(item);
  16.             }
  17.             stringToWrite.Flush();
  18.             stringToWrite.Close();
  19.         }
  20.  
  21.         private void LoadRecentList()
  22.         {
  23.             RecentList.Clear();
  24.             try
  25.             {
  26.                 StreamReader listToRead = new StreamReader(System.Environment.CurrentDirectory + "\\Recent.txt");
  27.                     //read file stream
  28.                 string line;
  29.                 while ((line = listToRead.ReadLine()) != null) //read each line until end of file
  30.                     RecentList.Enqueue(line); //insert to list
  31.                 listToRead.Close(); //close the stream
  32.             }
  33.             catch (Exception)
  34.             {
  35.                
  36.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement