0
votes

Hi this is the current version......please help.

'>

using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.IO;

public partial class Default2 : System.Web.UI.Page { private void BindGrid() { DirectoryInfo dir = new DirectoryInfo("D:/Pilabs Projects/GlobeDse/globedse website/globedse.com/Uploads"); FileInfo[] files = dir.GetFiles(); GridView1.DataSource = files; GridView1.DataBind();

}

protected void Page_Load(object sender, EventArgs e)
{


    if (!Page.IsPostBack)
    {
         BindGrid();
    }




}

private void Downloadfile(String fileName, String FullFilePath)
{

    Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
    Response.TransmitFile(FullFilePath);
    Response.End();


}

protected void GridView1_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
{
    if (e.CommandName == "Download")
    {
        String[] fileInfo = e.CommandArgument.ToString().Split(';');
        String FileName = fileInfo[1].ToString();
        String FullPath = fileInfo[0].ToString();
        Downloadfile(FileName, FullPath);
    }

}


protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{

    GridView1.PageIndex = e.NewPageIndex
    BindGrid();


}

}

2
Have you checked that you enter the download code? If you don't, it may be your CommendNameLasse Espeholt

2 Answers

0
votes

First, check if your method Downloadfile is getting hit. You also did

Response.Write(FullPath);

which kinda ruins your output. I'd rather design it that you redirect to another page which outputs the download.

0
votes

You're missing a check for postbacks. Your Page_Load should look something like this:

protected void Page_Load(object sender, EventArgs e) 
{ 
  if (!Page.IsPostBack)
  {
    BindGrid();
  }
}

When you re-databind the grid, the events are lost.