Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,
I know this is a duplicate question. But I have tried several methods but couldn't find it.
I have a datagrid and a file download button. After the file is downloaded I need the page to be reloaded again.
How to do this.Any help will be really appreciated.

What I have tried:

try
         {


             string user = Session["user"].ToString();
             var document = new Document(PageSize.A4, 50, 30, 20, 20);

             var output = new MemoryStream();
             var writer = PdfWriter.GetInstance(document, output);
             document.Open();
             //var titleFont = FontFactory.GetFont("Arial", 18, Font.BOLD);
             var titleFont = FontFactory.GetFont("Verdana", 16, Font.BOLDITALIC, new Color(125, 88, 15));



             var itemsTable = @"<table>";
             itemsTable += string.Format("<font style=\"font-family: Verdana\" size=\"2\"><tr><td ><table border=\"0\"><tr><td  align=\"Left\" colspan=\"6\"><img src='" + pdfheader + "' height=\"30px\" width=\"100px\" style=border-style: none></td></tr><tr><td colspan=\"7\" align=\"Center\" style=\"background-color:#FFA28A;color:#000000;margin:100px;\" Height=\"30px\" Valign=\"middle\">Quotation NO : " + QotationID + "</td></tr></table></td> </tr>");
             for (int j = 0; j < grd_datalist.Rows.Count; j++)
             {
                   itemsTable += string.Format("<font style=\"font-family: Verdana\" size=\"2\"><tr><td ><table border=\"0\"><tr><td colspan=\"7\" align=\"Center\" style=\"background-color:#ffffff;color:#000000;margin:100px;\" Height=\"30px\" Valign=\"left\"> "+grd_datalist.Rows[j].Cells[2].Text  + " : " + grd_datalist.Rows[j].Cells[3].Text  + "</td></tr></table></td></tr>");
             }


             itemsTable += "<br/><br/><tr><td></td></tr><tr><td align=\"center\"  style=\"color:#000000;background-color:#FF0000;padding:5px;\" valign=\"middle\" >xxx Email info@ccc.ae Toll Free: 800 872 432 584 Phone+971 4 235 9116</td></tr></font></table>";
             ArrayList htmlarraylist = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new StringReader(itemsTable), null);
             //add the collection to the document
             for (int k = 0; k < htmlarraylist.Count; k++)
             {

                 document.Add((IElement)htmlarraylist[k]);
             }

             document.Close();

             Response.ContentType = "application/pdf";
             Response.AddHeader("Content-Disposition", string.Format("attachment;filename=Schedule-{0}.pdf", QotationID));
             Response.BinaryWrite(output.ToArray());
             ScriptManager.RegisterStartupScript(this, this.GetType(), "onload", "javascript:location.reload(true);", true);


         }
         catch (Exception exp)
         {

             Alert.Show(exp.Message.ToString());

         }
         finally
         {

             grd_view.DataBind();
             UpdatePanel2.Update();
             Session["gdxml"] = "";
             ClearTest();
             grd_datalist.DataBind();
             //quolists();
         }
     }

This is my file download code.Please help me.
Posted
Updated 23-Oct-17 17:09pm

You can't reload the page after a download and there is no way of knowing when the download completes or if the file is downloaded at all. You should instigate the download in a new tab, so if your download is a link then add target="_blank"

<a href="downloadfile.aspx?ID=123" target="_blank">download</a>


You could then reload the page on the click of that link. You haven't explained how you instigate the download so it's hard to give a specific solution.
 
Share this answer
 
Comments
Member 12926744 23-Oct-17 9:13am    
The file is downloaded on a button click.
F-ES Sitecore 23-Oct-17 9:28am    
If it submits a form then change the target of the form to "_blank" using javascript when the button is clicked, that will submit the form to a new tab and have the same effect.
refer my Article/Tip ASP.NET Export Excel - Show/Hide Loading Image[^]
do some slight modification to the code in such a way that instead of hiding the image after download, just reload the page with Location reload() Method[^]
 
Share this answer
 

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