Buenas tengo un problema estuve realizando un modulo para descargar excel y si funciona correctamente por la cual ahora estoy subiendo ese modulo en un IISIIS
y si descarga pero cuando abre sale que el archivo esta dañado ademas se esta descargando en la carpeta de descargas ya que yo le habriahabría puesto que se guarde en el disco C://C://
y si me genera correcta en mi servidor local localhost
Este es mi codigocódigo:
string query = "SP_ReporteExcel";
using (SqlConnection con = new SqlConnection(ObtenerCadenaConexion()))
{
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.CommandTimeout = 90000000;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("opt", SqlDbType.Int).Value = 1;
cmd.Parameters.Add("fechainicio", SqlDbType.DateTime).Value = txtFinicio.Text;
cmd.Parameters.Add("fechafin", SqlDbType.DateTime).Value = txtFFin.Text;
cmd.Parameters.Add("rubro", SqlDbType.VarChar, 250).Value = dprAgencia.SelectedItem.Value;
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataSet ds = new DataSet())
{
sda.Fill(ds);
//Set Name of DataTables.
ds.Tables[0].TableName = "Recibos-Energia Electrica";
ds.Tables[1].TableName = "Recibos-Agua Potable";
using (XLWorkbook wb = new XLWorkbook())
{
foreach (DataTable dt in ds.Tables)
{
DateTime d3 = DateTime.Parse(txtFinicio.Text);
string Mes = d3.ToString("MMMM");
DateTime d4 = DateTime.Parse(txtFinicio.Text);
string Anio = d4.ToString("yyyy");
wb.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
wb.Style.Font.Bold = true;
wb.Style.Font.FontColor = XLColor.Black;
//wb.Style.Font.FontName = "calibri";
//wb.Style.Font.FontSize = 13;
wb.Style.Border.DiagonalBorderColor = XLColor.Red;
wb.Style.Border.RightBorderColor = XLColor.Red;
wb.Style.Border.LeftBorderColor = XLColor.Red;
wb.Style.Border.BottomBorderColor = XLColor.Red;
var ws = wb.Worksheets.Add(dt);
ws.Row(1).InsertRowsAbove(1);
ws.Cells("A2:H2").Style.Fill.BackgroundColor = XLColor.Black;
ws.Cells("A2:H2").Style.Font.FontColor = XLColor.Yellow;
ws.Cells("D1:H1").Style.Fill.BackgroundColor = XLColor.Black;
ws.Cells("D1:H1").Style.Font.FontColor = XLColor.Yellow;
string datetimeStringFileName = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
ws.Range("D1:H1").Merge();
ws.Range("D1").Value = "Mes de " + Mes + " del " + Anio;
//ws.Cells("D1:H1").Value = "Mes";
//wb.Style.Fill.BackgroundColor = XLColor.Black;
//wb.Worksheets.Add(dt);
}
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment;filename=\"Reporte_Mensuales.xlsx\"");
using (MemoryStream MyMemoryStream = new MemoryStream())
{
var aux = Guid.NewGuid();
wb.SaveAs("C:\\DatosSiga\\Logistica\\Reporte_Mensualess" + aux + ".xlsx");
MyMemoryStream.WriteTo(Response.OutputStream);
Response.Flush();
Response.End();
Response.Redirect("FrmLogeo.aspx");
}
}
}
}
string query = "SP_ReporteExcel";
using (SqlConnection con = new SqlConnection(ObtenerCadenaConexion()))
{
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.CommandTimeout = 90000000;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("opt", SqlDbType.Int).Value = 1;
cmd.Parameters.Add("fechainicio", SqlDbType.DateTime).Value = txtFinicio.Text;
cmd.Parameters.Add("fechafin", SqlDbType.DateTime).Value = txtFFin.Text;
cmd.Parameters.Add("rubro", SqlDbType.VarChar, 250).Value = dprAgencia.SelectedItem.Value;
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataSet ds = new DataSet())
{
sda.Fill(ds);
//Set Name of DataTables.
ds.Tables[0].TableName = "Recibos-Energia Electrica";
ds.Tables[1].TableName = "Recibos-Agua Potable";
using (XLWorkbook wb = new XLWorkbook())
{
foreach (DataTable dt in ds.Tables)
{
DateTime d3 = DateTime.Parse(txtFinicio.Text);
string Mes = d3.ToString("MMMM");
DateTime d4 = DateTime.Parse(txtFinicio.Text);
string Anio = d4.ToString("yyyy");
wb.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
wb.Style.Font.Bold = true;
wb.Style.Font.FontColor = XLColor.Black;
//wb.Style.Font.FontName = "calibri";
//wb.Style.Font.FontSize = 13;
wb.Style.Border.DiagonalBorderColor = XLColor.Red;
wb.Style.Border.RightBorderColor = XLColor.Red;
wb.Style.Border.LeftBorderColor = XLColor.Red;
wb.Style.Border.BottomBorderColor = XLColor.Red;
var ws = wb.Worksheets.Add(dt);
ws.Row(1).InsertRowsAbove(1);
ws.Cells("A2:H2").Style.Fill.BackgroundColor = XLColor.Black;
ws.Cells("A2:H2").Style.Font.FontColor = XLColor.Yellow;
ws.Cells("D1:H1").Style.Fill.BackgroundColor = XLColor.Black;
ws.Cells("D1:H1").Style.Font.FontColor = XLColor.Yellow;
string datetimeStringFileName = string.Format("{0:yyyy-MM-dd}", DateTime.Now);
ws.Range("D1:H1").Merge();
ws.Range("D1").Value = "Mes de " + Mes + " del " + Anio;
//ws.Cells("D1:H1").Value = "Mes";
//wb.Style.Fill.BackgroundColor = XLColor.Black;
//wb.Worksheets.Add(dt);
}
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment;filename=\"Reporte_Mensuales.xlsx\"");
using (MemoryStream MyMemoryStream = new MemoryStream())
{
var aux = Guid.NewGuid();
wb.SaveAs("C:\\DatosSiga\\Logistica\\Reporte_Mensualess" + aux + ".xlsx");
MyMemoryStream.WriteTo(Response.OutputStream);
Response.Flush();
Response.End();
Response.Redirect("FrmLogeo.aspx");
}
}
}
}
}
}