Click here to Skip to main content
15,904,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Guys,
I have a issue.i am a making gridview double clikable. doubleclick on row i am calling a function name selectrow(rowindex) and inside function i am calling a javascript __dopostback('selectrow',rowindex) function.on pageload i am taking the value of Request.Form["__EVENTTARGET"] and Request.Form["__EVENTTARGET"] and check if Request.Form["__EVENTTARGET"]&&Request.Form["__EVENTTARGET"] not null then take the index of gridview selected row and call a function to download file listed in colum.till here fine.but after clicking on any button same vale of Request.Form["__EVENTTARGET"]&&Request.Form["__EVENTTARGET"] comes and downloadin start again.if button is not inside updatepannel if button is inside updatepannel javascript runtime error comes.



this is my code to function download

C#
System.IO.FileInfo FileName = new System.IO.FileInfo(_Filename);
if (FileName.Exists)
{
   FileStream myFile = new FileStream(_Filename, FileMode.Open,FileAccess.Read,FileShare.Write);
                    BinaryReader _BinaryReader = new BinaryReader(myFile);
                    long startBytes = 0;
                    string lastUpdateTiemStamp = File.GetLastWriteTimeUtc(_Filename).ToString("r");
                    string _EncodedData = HttpUtility.UrlEncode(_Filename, Encoding.UTF8) + lastUpdateTiemStamp;
                    Response.Clear();
                    Response.Buffer = false;
                    Response.AddHeader("Accept-Ranges", "bytes");
                    Response.AppendHeader("ETag", "\"" + _EncodedData + "\"");
                    Response.AppendHeader("Last-Modified", lastUpdateTiemStamp);
                    Response.ContentType = "application/octet-stream";
                    Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName.Name);
                    Response.AddHeader("Content-Length", (FileName.Length - startBytes).ToString());
                    Response.AddHeader("Connection", "Keep-Alive");

                    //Set the Content Encoding type
                    Response.ContentEncoding = Encoding.UTF8;

                    //Send data

                    _BinaryReader.BaseStream.Seek(startBytes, SeekOrigin.Begin);
                    int maxCount = (int)Math.Ceiling((FileName.Length - startBytes + 0.0) / 1024);
                    int i=0;
                    try
                    {
                        for (i = 0; i < maxCount && Response.IsClientConnected; i++)
                        {
                            Response.BinaryWrite(_BinaryReader.ReadBytes(1024));
                            Response.Flush();
                            if (i == maxCount - 1)
                            {
                                _BinaryReader.Close();
                               
                            }

                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    finally
                    {
                        _BinaryReader.Close();
                        File.Delete(outputFile);
                    }
                  
                    if (i < maxCount)
                    {
                        MessageBox.Show("Error in downloading");
                        //Response.Write("<script language=javascript>confirm('Error in downloading')");
                    }
}


and on pageload this is my code

//////////////////
C#
string source = Request.Form["__EVENTTARGET"];
       string value = Request.Form["__EVENTTARGET"];

C#
if (!string.IsNullOrEmpty(source) && !string.IsNullOrEmpty(value))
       {

           if (source.ToLower().Equals("selectrow"))
           {

               int SelectedRow = int.Parse(value);
               string text = path + "\\" + GridView1.Rows[SelectedRow].Cells[0].Text;
               Download(text);
Posted
Updated 10-Aug-12 10:59am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900