I want Datatable to Excel automatically creating new folder and writing into it

I want to create a new folder automatically when I write into excel. That excel should be there in new folder with current date and time. So it becomes easy to identify. How should I do it can someone show with screen shot or an example.

Thankyou

Hi @Bhushan_Nagaonkar ,

You could try using the Create Folder Activity with the Expression of current date and time like below :

  1. Create a variable called FolderPath assign the value like below :
FolderPath = Path.Combine(Environment.CurrentDirectory,Now.ToString("dd_MM_yy_HH_mm_ss"))
  1. Next use the Create Folder activity with the above variable as the value.

  2. When writing the data to Excel file mention the path like below.

Path.Combine(FolderPath,"yourExcelFilePathName.xlsx")

Visuals :
image

Let us know if this is not what was expected.

1 Like

Thanks I will let you know asap

1 Like


This is the error. It says Combine and Now are not the members of the string

@Bhushan_Nagaonkar ,

Apologies. A bracket is again needed to be added at the end. I have updated the expression in the post above.

1 Like

I have already updated the bracket the error is combine and now are not part of the string

@Bhushan_Nagaonkar ,

After CurrentDirectory there is a comma , not a .

1 Like

“Now” is fixed but still got an issue for “Combine”

@Bhushan_Nagaonkar ,

Could you show a Screenshot of the error received ?

1 Like

@Bhushan_Nagaonkar ,

Change the variable name to FolderPath, if you could observe in my earlier post, Path is different and FolderPath is different.

Path is a reserved word like System, hence we cannot use it as a variable.

1 Like

From NewFolder to FolderPath or from Path

Ok I got it now

1 Like

Still same
No change in error

@Bhushan_Nagaonkar ,

Could you delete the Path variable created as well.

I have deleted it. I will share a screen shot


I also tried writing Folder Path in place of Path
Assign show ILocalResource should I change it to string

@Bhushan_Nagaonkar ,

Yes. The datatype should be string.

However, there is a lot of confusion. Do change it to string and if there are any further conflicts, Try to do the steps mentioned in the post above from the Start. Else we could provide a xaml.

1 Like

Thanks it really worked. I did the changes. One more question can I save this in the folder I want

Yes. In that case, you would require to modify the FolderPath or NewFolder variable value assignment in the below way :

Path.Combine("YourFolderPath",Now.ToString("dd_MM_yy_HH_mm_ss"))

Notice that, previously I had used Environment.CurrentDirectory to create the Folder in the project’s directory.