Hello Nikil0012
I re-written some of your code hope you don't mind :)
I think their are two possible solutions of your problem. all the solutions are depending on the situation.
I've tried to explain the code by addin some comment. If you have any questions don't hesitate to post them.
public void test()
{
string day = DateTime.Today.Day.ToString().PadLeft(2,'0');
string month = DateTime.Today.Month.ToString().PadLeft(2,'0');
string path = string.Format(@"D:\TransactionRequest\{0}_{1}_{2}", day, month, DateTime.Now.Year);
CheckOrCreateFolder(path);
path = string.Format(@"D:\TransactionRequest\ContractMaster{0}_{1}_{2}", day, month, DateTime.Now.Year);
CheckOrCreateFolder(path);
string path1 = string.Format(@"D:\TransactionRequest\{0}_{1}_{2}", day, month, DateTime.Now.Year);
string path2 = string.Format(@"D:\TransactionRequest\ContractMaster{0}_{1}_{2}", day, month, DateTime.Now.Year);
CheckOrCreateFolder(path1);
CheckOrCreateFolder(path2);
}
And the extra method
public void CheckOrCreateFolder(string path)
{
try
{
if (!(Directory.Exists(path)))
{
Directory.CreateDirectory(path);
}
}
catch (Exception)
{
throw;
}
}