This solved my issue-- I can generate, preview(in new browser window) and save to a specified server directory using a dynamic name
public ActionResult AuditTrail()
{
string batch = string.Empty;
batch = System.Web.HttpContext.Current.Session["BatchId"].ToString();
SqlConnection con = new SqlConnection(Helpers.DatabaseConnect);
DataTable dt = new DataTable();
try
{
DateTime Today = DateTime.Today;
var startdate = new DateTime(Today.Year, Today.Month, 1);
var enddate = startdate.AddMonths(1).AddDays(-1);
con.Open();
SqlCommand cmd = new SqlCommand("SELECT Action,CreatedBy,CreatedOn,Entity,Username,Checker FROM Trail ", con);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(dt);
}
catch (Exception ex)
{
ViewBag.ErrorMessage = Helpers.Messages.GENERAL_ERROR;
return View();
}
string OutputFileName = batch;
ReportClass rptH = new ReportClass();
rptH.FileName = Server.MapPath(("~/Reports/") + "AuditTrail.rpt");
rptH.Load();
rptH.SetDataSource(dt);
string filePath = Server.MapPath("~/GeneratedReports/") + OutputFileName + ".pdf";
rptH.ExportToDisk(ExportFormatType.PortableDocFormat, filePath);
Stream stream = rptH.ExportToStream(ExportFormatType.PortableDocFormat);
return File(stream, "application/pdf");
}
However im getting error
'The given path's format is not supported' when i try naming the file as i would want . ie using the BatchId and the current month-end date :
string batch = string.Empty;
batch = System.Web.HttpContext.Current.Session["BatchId"].ToString();
DateTime Todayy = DateTime.Today;
var startdatte = new DateTime(Todayy.Year, Todayy.Month, 1);
var enddatte = startdatte.AddMonths(1).AddDays(-1);
var monthend = enddatte.ToString();
string OutputFileName = batch + " " + monthend;
string filePath = Server.MapPath("~/GeneratedFolder/") + OutputFileName + ".pdf";
rptH.ExportToDisk(ExportFormatType.PortableDocFormat, filePath);