#region using (StringWriter sw = new StringWriter()) { using (HtmlTextWriter hw = new HtmlTextWriter(sw)) { //To Export all pages grdaccinfodatewise.AllowPaging = false; //Calling the Function BindGrid(), here im adding the data to the Datasource and diplaying in Grid BindGrid(); grdaccinfodatewise.RenderControl(hw); StringReader sr = new StringReader(sw.ToString()); Document pdfDoc = new Document(PageSize.A3, 10f, 10f, 10f, 10f); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); pdfDoc.NewPage(); string imageURL = Server.MapPath(".") + "/img/bank_logo.png"; iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageURL); jpg.SpacingBefore = 10f; jpg.SpacingAfter = 1f; jpg.Alignment = Element.ALIGN_CENTER; pdfDoc.Add(jpg); if (rdbtnbydate.Checked == true) { pdfDoc.Add(new Phrase("\r\nAccount Statement From " + this.dateMinFilter.Text.Trim() + " To " + this.dateMaxFilter.Text.Trim() + "\r\n\r\n")); pdfDoc.Add(new Phrase("ACCOUNT NUMBER : " + Session["loginaccno"].ToString().Trim())); pdfDoc.Add(new Phrase("\r\nCUSTOMER NAME : " + Session["CustName"].ToString().ToUpper().Trim())); pdfDoc.Add(new Phrase("\r\nAccount Type : " + ViewState["SchemeName"].ToString().ToUpper().Trim())); } if (rdbtnmonth.Checked == true) { pdfDoc.Add(new Phrase("\r\nAccount Statement for the Month of : " + this.ddlmonth.SelectedItem.ToString().ToUpper().Trim() + " - " + this.txtyear.Text.Trim() + "\r\n")); pdfDoc.Add(new Phrase("\r\nCUSTOMER NAME : " + Session["CustName"].ToString().ToUpper().Trim())); pdfDoc.Add(new Phrase("\r\nACCOUNT NUMBER : " + Session["loginaccno"].ToString().Trim() + "\r\n\r\n")); } htmlparser.Parse(sr); pdfDoc.Close(); Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=pdfExport.pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Write(pdfDoc); HttpContext.Current.ApplicationInstance.CompleteRequest(); } } } catch (Exception ex) { throw ex; } finally { } #endregion
throw ex;
throw;
catch (Exception ex){ // Do something with the exception here... throw;}
try..catch
try
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)