Click here to Skip to main content
15,881,027 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I need a class Entry with properties Name, and collection of Emails, and with the ability to
Save and Load all properties to/from local file system

Thanks OriginalGriff

i know that i need a Save() and Load() method thats the part i need help with

So i looked around a little more this is what i got

C#
class Entry
    {
        
        public string Name { get; set; }
        public IEnumerable<string> Emails { get; set; }
        
        public void Save()
        {
            TextWriter tsw = new StreamWriter(@"C:\Emails.txt");
            tsw.WriteLine(Name);
            tsw.WriteLine();
            foreach (string email in Emails)
            {
                tsw.WriteLine(email);
            }
            tsw.Close();
            Process.Start(@"C:\Emails.txt");


        }
        
        public void Load()
        {
            TextReader trs = new StreamReader(@"C:\Emails.txt");
            Console.WriteLine(trs.ReadToEnd());
            trs.Close();
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
    }

dows any one have any sugestions or critics?
Posted
Updated 29-May-14 23:14pm
v4
Comments
Stephen Hewison 30-May-14 3:54am    
So what's the problem? What have you tried so far? What problems have you run into?
Member 10853954 30-May-14 4:14am    
Well i dont know how to create the save and load methods
Mehdi Gholam 30-May-14 3:55am    
...and what have you done so far and what is your problem?
CHill60 30-May-14 4:15am    
"that's the part i need help with" ... then share with us what have tried so far, explain where you are stuck and we may be able to help.
Member 10853954 30-May-14 4:20am    
i browsed the net on how this sould be done, do i use streamReader if so how do i do it, i really cant figure it out

1 solution

C#
public class Entry
   {
   public string Name { get; set; }
   public IEnumerable<Email> Emails { get; set; }
   public void Save()
      {
      }
   public void Load()
      {
      }
   }
The methods are left as an exercise for the reader.
 
Share this answer
 
Comments
Member 10853954 30-May-14 4:04am    
Thank you for your reply but is it really that easy?
DamithSL 30-May-14 4:09am    
:)
Kenneth Haugland 30-May-14 4:12am    
Try again, the OP think it should be harder! :laugh:
Karthik_Mahalingam 30-May-14 5:00am    
:)
Sprint89 30-May-14 6:00am    
Are you asking how to call the Save and Load methods?

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