I read all line from file text into List<>.
But I have a problem. I want to change only 1 element(is columns) in 1 rows of file text.
When I send Email successful, it will update time in this line I checking.
This data in file text
User1 abc@gmail.com 5/1/2016
// many rows.....
After SendEmail successful it's will update like:
User1 abc@gmail.com 8/1/2016
Current, I must use AppendAllLine() function to add line:
File.AppendAllLines(dataPath, (from i in Items select i.Serialize()).ToArray(), Encoding.Default);
I tried StreamWriter but it does not support like:
from i in Items select i.Serialize()).ToArray()
Here my code to update time.
if (time.Day == today.Day)
{
flag = SendMail.sendDailyMail(listMail);
if (flag == true)
{
rows.time = timeNow;
List<DTOSaveFromFile> lst = new List<DTOSaveFromFile>(1);
lst.Add(rows);
DiskFile.Save(lst);
}
}
Class DiskFile:
public static void Save(List<DTOSaveFromFile> Items)
{
File.AppendAllLines(dataPath, (from i in Items select i.Serialize()).ToArray(), Encoding.Default);
}
public static List<DTOSaveFromFile> Load()
{
string[] data = File.ReadAllLines(dataPath);
return (from i in data select new DTOSaveFromFile(i)).ToList<DTOSaveFromFile>();
}