Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi,
i want to export my gridview in pdf and Excel but the extension doesn't display thi's my code

private void ExportGridToExcel()
{
Response.Clear();
Response.Buffer = true;
Response.ClearContent();
Response.ClearHeaders();
Response.Charset = "";
string FileName = "WebQ-Tel-Data" + DateTime.Now + ".xls";
StringWriter strwritter = new StringWriter();
HtmlTextWriter htmltextwrtter = new HtmlTextWriter(strwritter);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName);
GridView1.GridLines = GridLines.Both;
GridView1.HeaderStyle.Font.Bold = true;
GridView1.RenderControl(htmltextwrtter);
Response.Write(strwritter.ToString());
Response.End();

}

private void ExportGridToPDF()
{

Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=WebQ-Tel-Data" + DateTime.Now + ".pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView1.HeaderRow.Cells[0].Text = "Date et heure";
GridView1.HeaderRow.Cells[0].ForeColor = Color.Black;
GridView1.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
GridView1.AllowPaging = true;
GridView1.DataBind();
}


but in google chrome it works
plzz i need help
Posted
Comments
F-ES Sitecore 22-Jun-15 6:56am    
What do you mean by "the extension doesn't show"?
Member 11573837 22-Jun-15 7:00am    
hi F-ES Sitecore,
thank you for answering me, whene i clic to exporting pdf using google chrom i havi file lif WebQ-Tel-Data.pdf or WebQ-Tel-Data.xls but when i user mozila firefox ia have file like WebQ-Tel-Data and WebQ-Tel-Data without extension
F-ES Sitecore 22-Jun-15 7:16am    
It's probably just hiding the extension from you, is this causing a problem?
Member 11573837 22-Jun-15 7:23am    
but whene the user want to export pdf o excel using mozila firefox don't apear extention like me

1 solution

Its not about the code. Its about the selection of Hide known extensions or not.
Follow this image[^]

To access this go to organise of your explorer -> Folder & Search Option -> View tab

unchecked the check box and you can also view the extension when you will download.

And it will be different computer wise.
 
Share this answer
 
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