Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. static void Main(string[] args)
  2. {
  3. //Assigns the variables
  4. int option;
  5. string store;
  6.  
  7.  
  8.  
  9. //Sets the text colour
  10. Console.ForegroundColor = ConsoleColor.DarkMagenta;
  11. //Sets the background colour
  12. Console.BackgroundColor = ConsoleColor.Gray;
  13. //Allows the background colour to be seen over the entire of the screen
  14. Console.Clear();
  15.  
  16. //Menu, with options for the user to select
  17. Console.WriteLine("-----------------------------------------");
  18. Console.WriteLine("| Menu |");
  19. Console.WriteLine("-----------------------------------------");
  20. Console.WriteLine("| 1. Search for file ... |");
  21. Console.WriteLine("| 2. Enter Search String |");
  22. Console.WriteLine("| 3. Print and store search result file |");
  23. Console.WriteLine("| 4. Another search ??? |");
  24. Console.WriteLine("-----------------------------------------");
  25.  
  26. //Asks the user to select one of the options above
  27. Console.WriteLine(" Please select ONE of the above options ");
  28.  
  29. //Converts variable 'option' to an integer
  30. option = Convert.ToInt32(Console.ReadLine());
  31.  
  32. //If the user selects
  33. if (option == 1)
  34. {
  35. do
  36. {
  37. try
  38. {
  39. string UserInput = "files\\" + Console.ReadLine() + ".txt";
  40. FileStream file = new FileStream(UserInput, FileMode.Open, FileAccess.Read);
  41. StreamReader sr = new StreamReader (file);
  42. store = sr.ReadToEnd();
  43. sr.Close();
  44. file.Close();
  45. Console.WriteLine(store);
  46. Console.ReadLine();
  47.  
  48. break; //this will end the loop once the code runs right
  49. }
  50. catch
  51. {
  52. Console.WriteLine("The file name entered is not valid");//put the stuff that you want to happen when the above code fails, in here!
  53. }
  54.  
  55. } while (true);
  56. }
  57.  
  58.  
  59. if (option == 2)
  60. {
  61. Console.WriteLine("Please enter the required string");
  62. string UserInput = Console.ReadLine();
  63.  
  64. }
  65.  
  66. if (option == 3)
  67. {
  68. //FileStream file = new FileStream();
  69. }
  70.  
  71. if (option == 4)
  72. {
  73.  
  74. }
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81. Console.ReadLine();
  82.  
  83. }
  84. public static string SearchString;
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement