I have a text file with information:
Template PUC
C# Assignment.
Path=E:\Project_Excel.xlsx
Path= EMailId=abc@xyz.com; def@xyz.com; ghi@xyz.com
I am parsing the text file using C# and looking for "Path=" and extract the path after "=" and open it for further operation. If "Path=" has no path mentioned then it should ask user to enter the path manually on console window. Can anyone please help me where I am going wrong?
- static void Main(string[] args)
- {
- try
- {
- string file = "E:\\Project_PU.txt";
- StreamReader sr = new StreamReader(file);
- String lines = sr.ReadToEnd();
-
- int x = lines.IndexOf('=');
- int y = lines.IndexOf('_');
- string x = lines.Substring(x + 1, y - x);
-
-
- string mail = File.ReadAllLines(file).FirstOrDefault(line => line.StartsWith("EmailId="));
- string sString = mail;
- string[] sLines = sString.Split(new string[] { "EmailId=", ";" }, StringSplitOptions.RemoveEmptyEntries);
-
-
- Excel.Application xlApp;
- Excel.Workbook xlWorkBook;
- Excel.Worksheet xlWorkSheet;
- Excel.Range range;
-
- long rowCount;
- long rw = 0;
- long cl = 0;
-
- xlApp = new Excel.Application();
-
- string path = "";
- Console.WriteLine();
- Console.WriteLine();
-
-
- if (File.Exists(path))
- {
-
- xlWorkBook = xlApp.Workbooks.Open(path, 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);