Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- //Assigns the variables
- int option;
- string store;
- //Sets the text colour
- Console.ForegroundColor = ConsoleColor.DarkMagenta;
- //Sets the background colour
- Console.BackgroundColor = ConsoleColor.Gray;
- //Allows the background colour to be seen over the entire of the screen
- Console.Clear();
- //Menu, with options for the user to select
- Console.WriteLine("-----------------------------------------");
- Console.WriteLine("| Menu |");
- Console.WriteLine("-----------------------------------------");
- Console.WriteLine("| 1. Search for file ... |");
- Console.WriteLine("| 2. Enter Search String |");
- Console.WriteLine("| 3. Print and store search result file |");
- Console.WriteLine("| 4. Another search ??? |");
- Console.WriteLine("-----------------------------------------");
- //Asks the user to select one of the options above
- Console.WriteLine(" Please select ONE of the above options ");
- //Converts variable 'option' to an integer
- option = Convert.ToInt32(Console.ReadLine());
- //If the user selects
- if (option == 1)
- {
- do
- {
- try
- {
- string UserInput = "files\\" + Console.ReadLine() + ".txt";
- FileStream file = new FileStream(UserInput, FileMode.Open, FileAccess.Read);
- StreamReader sr = new StreamReader (file);
- store = sr.ReadToEnd();
- sr.Close();
- file.Close();
- Console.WriteLine(store);
- Console.ReadLine();
- break; //this will end the loop once the code runs right
- }
- catch
- {
- Console.WriteLine("The file name entered is not valid");//put the stuff that you want to happen when the above code fails, in here!
- }
- } while (true);
- }
- if (option == 2)
- {
- Console.WriteLine("Please enter the required string");
- string UserInput = Console.ReadLine();
- }
- if (option == 3)
- {
- //FileStream file = new FileStream();
- }
- if (option == 4)
- {
- }
- Console.ReadLine();
- }
- public static string SearchString;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement