Storing file by creating datefolders and saving inside it


I want to store excel file Inside date folder which I will create dynamically. So I wrote the code Like below

public void ExportExcel(string strWorkbookName, DataSet ds) { string strFilePath = ""; string strDateFolder = ""; try { using (XLWorkbook wb = new XLWorkbook()) { wb.Worksheets.Add(ds); //wb.SaveAs(ConfigurationRead.GetAppSetting("ReportDirectory") + "Report.xlsx"); strDateFolder = Directory.CreateDirectory(DateTime.Now.ToString("dd-MM-yyyy")); strFilePath = ConfigurationRead.GetAppSetting("ReportDirectory") + "\\" + strDateFolder + "\\" + "Report.xlsx"; } } catch (Exception) { throw; } }

But even the folder is not created and I get error as


cannot implicitly convert type system io directoryinfo to string


at line:-

strDateFolder = Directory.CreateDirectory(DateTime.Now.ToString("dd-MM-yyyy"));


I think you need something like that:

string reportDirectory = ConfigurationRead.GetAppSetting("ReportDirectory"); strDateFolder = Directory.CreateDirectory( Path.Combine(reportDirectory, DateTime.Now.ToString("dd-MM-yyyy"))).Name; strFilePath = Path.Combine(reportDirectory, strDateFolder, "Report.xlsx");

Hope this works. Could not fully check it.


  • Access TransferSpreadsheet - Replace Data
  • Fields in the wrong order when importing from CSV to Access
  • How to convert Excel values to datetime format in C#
  • Excel Process will not terminate with Excel-Introp
  • How to access the System.ComponentModel.DataAnnotations Display name property for a field
  • remove non-ASCII characters (using Microsoft.Office.Interop.Excel)
  • Remove all formatting of the table created from InsertTable method in ClosedXML
  • DVCS, Databases, and User Generated Content?
  • What happens when I strip one version of a mercurial repository and try to synchronize with another
  • How to configure nested dependency in ASP.NET 5 DI?
  • Upgrade from Eclipse Mars to Photon on Ubuntu cause problems
  • Convert Json to List with .NET
  • EGit and multiple “users” on same machine
  • Why do I need to force git to sync my remote repository?
  • gridview on page won't refresh, even when calling databind again
  • LibGit2Sharp CheckoutPaths()
  • Maven release with jenkins slave and Credentials : how to pass SCM credentials to maven?
  • sequel trying to use postgresql instead of postgres as adapters
  • Different version of file in Mercurial repo
  • Excel Range in C# using interop.Excel. Range both empty and not empty?
  • Unselect column after pasting data
  • No internet connectivity inside docker container running inside kubernetes with weave as networking
  • Google Cloud Builder - Gradle
  • how to insert new rows with values in the same sheet of an excel file in java
  • Referencing external dependencies in GGTS by convention
  • force insert with spring data jpa
  • Removing levels from data frame read from CSV file - R
  • Using VBA to select a dynamic range of cells and create a chart
  • Google cloud datastore emulator init data
  • ASP.NET Gridview Paging Problem
  • android.app.PendingIntent cannot be accessed ouside the package
  • “git push” doing the same as “git fetch” from the remote
  • Selenium and Google - How do you use cookies?
  • Keep same scale in different graphs ggplot2
  • Stacked Bar Chart with percentage composition inside the Bar and total above the Bar in JFreeChart
  • Can you use DataSet and DataTables in a Portable Class Library
  • C# Excel interop - how to test if interop object is still working and performing a task?
  • How to return DataSet (xsd) in WCF
  • Microsoft Visual Studio Community 2015 always crashes in Windows 10 if swithed to Visual FoxPro
  • json Serialization in asp