I have used this to save my file
string m_strDate = DateTime.Now.ToString("MM/dd/yyyy");
m_strDate = m_strDate.Replace("/", "");
strPath += "/FileHeader_" + m_strDate + ".txt";
So as per this I can save a file per day. But if I create for another time the data in that text file is getting replaced by the new one. Now what I need is I would like to save my file with some name along with date and a number like
"/FileHeader_1" + m_strDate + ".txt"
and so on.
strPath = "/FileHeader_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt";
or check if the file exists:
strPath = "/FileHeader_{0}" + DateTime.Now.ToString("MMddyyyy") + ".txt";
if ( File.Exists( string.format( strPath, "" ) ){
int i = 1;
while( File.Exists(string.format( strPath, i ) ){ i++ ; }
strPath = string.Format(strPath, i);
}
else {
strPath = string.format( strPath, "" );
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With