using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; using System.Data; namespace SistemaIAN { public partial class Descargas : Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Cargo_Grilla(); } } protected void Exportar_Click(object sender, EventArgs e) { //if (FileUpload1.HasFile) //{ // FileUpload1.PostedFile.SaveAs(Server.MapPath("~/Data/") + FileUpload1.FileName); //} Cargo_Grilla(); } private void Cargo_Grilla() { DataTable dt = new DataTable(); dt.Columns.Add("File", typeof(string)); dt.Columns.Add("Size", typeof(string)); dt.Columns.Add("Type", typeof(string)); foreach (string strFile in Directory.GetFiles(Server.MapPath("~/Data/"))) { FileInfo fi = new FileInfo(strFile); dt.Rows.Add(fi.Name,fi.Length, GetFileTypeByExtension(fi.Extension)); } GridView1.DataSource = dt; GridView1.DataBind(); } private string GetFileTypeByExtension(string extension) { switch (extension.ToLower()) { case ".exe": return "Aplicaciones"; case ".zip": return "ZIP"; default: return "unknow"; } } protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Download") { Response.Clear(); Response.ContentType = "application/octect-stream"; Response.AppendHeader("content-disposition", "filename=" + e.CommandArgument); Response.TransmitFile(Server.MapPath("~/Data/") + e.CommandArgument); Response.End(); } } } }