public async Task <IHttpActionResult> ExportMediaNewsToExcel(MediaSearchModel model) { var userId = User.Identity.GetUserId <int>(); DateTime?fromDate = null, toDate = null; string pathnew = Request.RequestUri.AbsolutePath; if ((!String.IsNullOrEmpty(model.startDate))) { fromDate = DateTime.ParseExact(model.startDate, "dd/MM/yyyy", CultureInfo.InvariantCulture); } if ((!String.IsNullOrEmpty(model.endDate))) { toDate = DateTime.ParseExact(model.endDate, "dd/MM/yyyy", CultureInfo.InvariantCulture); } var taskResult = repository.GeMediaListAll(userId, model.mediaTypeId, model.newsTypeIds, model.channelIds, model.categoryIds, model.sentimentIds, model.relevanceIds, model.createdBy, model.script, fromDate, toDate); var excelData = taskResult.MediaFormList; string baseUrl = ""; string excelFilename = "MediaNews" + DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + DateTime.Now.Millisecond + ".xls"; string SaveLocation = HttpContext.Current.Request.PhysicalApplicationPath + "Files\\" + excelFilename; DataTable dt = CreateExcelFile.ListToDataTable(excelData); CreateExcelFile file = new CreateExcelFile(); string detail = file.CreateExcelSheet(dt, SaveLocation, new List <int>(), new List <int>(), new List <string>()); baseUrl = "Files/" + excelFilename; return(Ok(baseUrl)); }