Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string strFilePath = GL.Encriptacion.DecryptText(Page.Request.QueryString.Get("ifile"), "data");
- string sfilename = GL.Encriptacion.DecryptText(Page.Request.QueryString.Get("nombre"), "data");
- string se = Page.Request.QueryString.Get("se");
- EL.SBC_EJECUCION_PROCESO_DETALLE ej = new EL.SBC_EJECUCION_PROCESO_DETALLE();
- ej.ARC_ID = Convert.ToInt32(GL.Encriptacion.DecryptText(Page.Request.QueryString.Get("arch"), "data"));
- ej.EPROD_AVER_ID = Convert.ToInt32(GL.Encriptacion.DecryptText(Page.Request.QueryString.Get("vers"), "data"));
- ej.EPROC_ID = Convert.ToInt32(GL.Encriptacion.DecryptText(Page.Request.QueryString.Get("eproc"), "data"));
- EL.SBC_ARCHIVO archivo = new EL.SBC_ARCHIVO();
- archivo.ARC_ID = ej.ARC_ID;
- ej.INCLUIR = 1;
- List<EL.SBC_ARCHIVO> archivos = BL.SBC_ARCHIVO.Buscar(archivo);
- if (archivos.Count > 0)
- {
- archivo = archivos[0];
- }
- string extension = archivo.ARC_EXT;
- if (extension == string.Empty)
- {
- extension = "txt";
- }
- string iUrl = HttpUtility.UrlDecode(strFilePath + sfilename + "." + extension);
- DataTable dt = new DataTable();
- if (se == null || se == "")
- {
- dt = BL.SBC_EJECUCION_PROCESO_DETALLE.generarArchivoFull(ej);
- }
- else
- {
- dt = BL.SBC_EJECUCION_PROCESO_DETALLE.generarArchivo(ej);
- }
- if (extension == "xlsx")
- {
- XLWorkbook wb = new XLWorkbook();
- int l = (sfilename.Length <= 31) ? sfilename.Length : 31;
- if (se == "1")
- {
- //sheet.Row(1).Delete();
- var sheet = wb.Worksheets.Add(sfilename.Substring(0, l));
- sheet.FirstRow().FirstCell().InsertData(dt.Rows);
- wb.SaveAs(iUrl);
- //sheet.Range("A1", "A1").Delete(XLShiftDeletedCells.ShiftCellsUp);
- }
- else
- {
- var sheet = wb.Worksheets.Add(dt, sfilename.Substring(0, l));
- wb.SaveAs(iUrl);
- }
- GL.funcionalidades.abrirArchivo(extension, sfilename, strFilePath);
- System.IO.File.Delete(iUrl);
- }
- else
- {
- if (File.Exists(iUrl))
- {
- System.IO.File.Delete(iUrl);
- }
- using (StreamWriter sw = new StreamWriter(strFilePath + sfilename + "." + extension, false, Encoding.UTF8))
- {
- int iColCount = dt.Columns.Count;
- //Escribiendo las Columnas del DataTable.
- if (se != "1")
- {
- for (int i = 0; i < iColCount; i++)
- {
- sw.Write(dt.Columns[i]);
- if (i < iColCount - 1)
- {
- sw.Write(",");
- }
- }
- sw.Write(sw.NewLine);
- }
- // Escribiendo todas las Filas del DataTable.
- foreach (DataRow dr in dt.Rows)
- {
- for (int i = 0; i < iColCount; i++)
- {
- if (!Convert.IsDBNull(dr[i]))
- {
- sw.Write(dr[i].ToString());
- }
- if (i < iColCount - 1)
- {
- sw.Write(",");
- }
- }
- sw.Write(sw.NewLine);
- }
- sw.Close();
- }
- System.IO.FileInfo toDownload = new System.IO.FileInfo(iUrl);
- if (toDownload.Exists)
- {
- HttpContext.Current.Response.Clear();
- HttpContext.Current.Response.AddHeader("Content-Disposition",
- "attachment; filename=" + toDownload.Name);
- HttpContext.Current.Response.AddHeader("Content-Length",
- toDownload.Length.ToString());
- HttpContext.Current.Response.ContentType = "application/octet-stream";
- HttpContext.Current.Response.WriteFile(iUrl);
- HttpContext.Current.Response.End();
- }
- else
- {
- ScriptManager.RegisterStartupScript(Page, GetType(), "MyScript", "window.close();", true);
- }
- }
- }
- catch (Exception ex)
- {
- ScriptManager.RegisterStartupScript(Page, GetType(), "MyScript", "window.close();", true);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement