views:

197

answers:

1

I have a gridview inside an update panel which holds the list of uploaded files to application. I want, when a row is selected, on selectedIndexChanged event to return the file to be downloaded

here is the code

string path = MyFiles.Rows[filesGrid.SelectedIndex]["FilePath"].ToString();

        FileStream fl = null;
        try
        {
            fl = new FileStream(path, FileMode.Open);

            Response.AddHeader("Content-disposition", "attachment; filename=" + fl.Name);
            byte[] buff = new byte[fl.Length];
            fl.Read(buff, 0, buff.Length);
            Response.BinaryWrite(buff);
        }
        catch (Exception ex)
        {
            lblError.Text = "Unable to download the file";
            lblError.ForeColor = System.Drawing.Color.Red;
        }
        finally
        {
            if (fl != null)
                fl.Close();
        }

When I click select, I receive a javascript error "Error parsing near '%PDF-1.4%?? 2294 0'" and nothing is returned.

Has anybody faced this problem or does anybody know any possible solution to this?

Thanks in advance

A: 

I found the answer here

http://tgynther.blogspot.com/2009/02/aspnet-updatepanel-and-responsewrite.html

however, if you have one async and one sync trigger then it doesn't work

with one sync trigger, it works fine

Arian