Hi,
How to construct filename for the this(abc_{yyMMdd}_xyz_{HHmm}.txt) format, The function should return filename like this abc_140822_xyz_1446.txt.
Please post solution for this post.
Thanks in Advance
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Aug 22, 2014, 10:58 AM
When I tried it just now (UK time) the output was:
KalaiPosted Aug 22, 2014, 9:06 AM
http://www.codeproject.com/Questions/322056/search-files-in-directory-Csharp
Rajkumar RPosted Aug 22, 2014, 7:52 AM
I will pass this "abc_{yyMMdd}_xyz_{HHmm}" as an input parameter to the function. The function should return appropriate filename. Sometime the input parameter may be like this "abc_{yyMMdd_HHmm}." So the function should handle all the cases,
Thanks in Advance.
KalaiPosted Aug 22, 2014, 7:41 AM
public string GenerateFileName()
{
string yy = DateTime.Now.Year.ToString();
yy = yy.Substring(yy.Length - 2);
string mm = DateTime.Now.Month.ToString().Length == 1 ? "0" + DateTime.Now.Month.ToString() : DateTime.Now.Month.ToString();
string dd = DateTime.Now.Day.ToString().Length == 1 ? "0" + DateTime.Now.Day.ToString() : DateTime.Now.Day.ToString();
string filename = "abc_" + yy + mm + dd + "_xyz_" + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".txt";
return filename;
}