Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am not getting data ,but it showing System.IO.StreamReader

What I have tried:

C#
public class BaseEmployee
   {
       public int? Id;
       public string Name;
   }

   public class Employee : BaseEmployee
   {
       public string Address;


       public  static  Object Adding()
       {
           Employee employeeDetail = new Employee();
           Console.Write("Employee Id:");
           employeeDetail.Id = int.Parse(Console.ReadLine());

           Console.Write("Employee Name:");
           employeeDetail.Name = Console.ReadLine();
           Console.Write("Employee Address:");
           employeeDetail.Address = Console.ReadLine();
           return employeeDetail;

       }

       static void Main(string[] args)
       {
           string pathString = @"c:\SpecifiedFiles";
           System.IO.Directory.CreateDirectory(pathString);
           string fileName = "MyNewFile.txt";
           pathString = System.IO.Path.Combine(pathString, fileName);
           Console.WriteLine("Path to my file: {0}\n", pathString);
           Boolean p = true;

           while (p)
           {
               Console.WriteLine("Employee Record Managemnet system");
               Console.WriteLine("1)Add");
               Console.WriteLine("2)Edit");
               Console.WriteLine("3)Dispaly");
               Console.WriteLine("4)Delete");
               Console.WriteLine("Select operation");


               int option = int.Parse(Console.ReadLine());
               switch(option)
               {
                   case 1:
                         if (System.IO.File.Exists(pathString))
                        {
                           using (FileStream fs = new FileStream(pathString,FileMode.Open,FileAccess.Write))
                           {
                               StreamWriter writer = new StreamWriter(fs);
                               StringBuilder output = new StringBuilder();

                               writer.Write(Adding());
                              fs.Close();

                           }

                       }

                       break;


                   case 2:
                       if (System.IO.File.Exists(pathString))
                       {
                           FileStream fs1 = new FileStream(pathString, FileMode.Open, FileAccess.Read);


                               StreamReader sr = new StreamReader(fs1);

                           Console.WriteLine(sr.ReadToEnd());

                               Console.WriteLine(sr);

                           }

                       break;


               }

               }



           }
Posted
Comments
gggustafson 20-Oct-16 18:21pm    
You never create the file named pathString. Therefore both of the tests

if ( System.IO.File.Exists ( pathString ) )

fail. That means your program does nothing.

What are you trying to do?
manu_dhobale 22-Oct-16 5:35am    
This was duplicated and answered, please do not repost same question.
http://www.codeproject.com/Questions/1144413/How-to-store-data-and-retrieve-data-from-file-in-C

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900