i'm trying to convert a DataTable
to an excel-file but at the time of creation of file it gives me error: could not find part of path.
string strDirectorypath = HttpContext.Current.Server.MapPath("~/ExcelUpload/");
DateTime dtbatchtime = Convert.ToDateTime(strBatchProcesstime);
strBatchProcesstime = dtbatchtime.ToString("MM-dd-yyyy_hh_mm_ss");
string strFilename = "FailedExcel_" + strBatchProcesstime + ".csv";
string csvdownloadPath = Path.Combine(strDirectorypath, strFilename);
using (FileStream File_Stream = new FileStream(csvdownloadPath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
{
using (StreamWriter FileWriter = new StreamWriter(File_Stream))
{
FileWriter.BaseStream.Seek(0, SeekOrigin.End);
string[] columns = { "Opportunity Name", "Property Id", "Error Type", "Error Message", "Time" };//set columns here as in the Excel Sheet.
CreateColumns(FileWriter, columns);
FileWriter.WriteLine();
if (dtRecords.Rows.Count > 0)
{
for (int i = 0; i < dtRecords.Rows.Count; i++)
{
string[] values = {
dtRecords.Rows[i]["OpportunityName"].ToString(),
dtRecords.Rows[i]["PropertyId"].ToString(),
dtRecords.Rows[i]["ErrorType"].ToString(),
dtRecords.Rows[i]["ErrorMessage"].ToString(),
dtRecords.Rows[i]["TimeStamp"].ToString()
};
CreateColumns(FileWriter, values);
FileWriter.WriteLine();
}
}
}
}