0

I am trying to download an excel file but keep getting

hexadecimal value 0x1D is invalid character ' error

Please find my code below.

public static string GenerateRADownloadExcel(System.Data.DataTable downloadtable,long studyid, out string fileName)
{
    try
    {
        using (var wb = new XLWorkbook())
        {
            wb.Worksheets.Add(downloadtable);
            var raDataKey = Guid.NewGuid().ToString();
            fileName = "Study_" + studyid + "_ResearchActivityData_" + DateTime.Now.ToString("ddMMyy") + "_" + DateTime.Now.ToString("HHmm");

            var memoryStream = new MemoryStream();
            wb.SaveAs(memoryStream);

            memoryStream.Position = 0;
            HttpContext.Current.Session[raDataKey] = memoryStream;

            return raDataKey;
        }
    }
    catch(Exception ex)
    {
        throw ex;
    }
}

I get an exception on execution of wb.SaveAs(memoryStream);

rene
  • 41,474
  • 78
  • 114
  • 152
Ayk
  • 1

0 Answers0