Click here to Skip to main content
15,994,794 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I make a program for employee transfers from one database to other, using datagridview in vb.net, I am capable to update and insert transfer employee to other database, but...............

Now, I want to write those transfer record i.e. EmpId, EmpName, TransferFrom and TransferTo fields to in transfer.txt file, but here I make some changes, I mean, I make filename with (current date & .txt) like as dd-mm-yyyy (01-04-2013). If I transfer Employee today and file not exits on file location then, it would be create and write all values and if file exist on file location then append new transfered employee to that file....
Posted

1 solution

First off, do your date filename the other way round:
2012-04-01.txt
That way, they are automatically sorted by date rather than all the first of the month, all the second of the month, as so on - getting to the newest and oldest becomes extremely simple.

It's pretty simple, you don't even need to check if the file exists:
XML
List<string> lines = new List<string>();
lines.Add("user 1, " + DateTime.Now);
lines.Add("user 2, " + DateTime.Now);
File.AppendAllLines(@"D:\Temp\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", lines);
The various File.AppendXXX methods create the file if it doesn't exist, and add the data if it does.
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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