iTextSharp: The process cannot access the file because it is being used by another process

Last Reply on Mar 13, 2014 11:30 PM By Mudassar

Posted on Mar 13, 2014 03:09 AM

 

  Document Doc = new Document(PageSize.A4, 10f, 10f, 10f, 10f);
            PdfWriter.GetInstance(Doc, new FileStream(Server.MapPath("~/GNM/") + "//marksheet.pdf", FileMode.Create));
            Doc.Open();
            for (int i = 0; i < GridView1.Rows.Count; i++)            {
                CheckBox chk = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
                if (chk.Checked == true)                {
                    con.Open();
                    string roll = (((Label)GridView1.Rows[i].Cells[2].FindControl("Label3")).Text).ToString();
                    SqlDataAdapter adp = new SqlDataAdapter("select * from GNM1styr_2014_15 where roll_no='" + roll + "'", con);
                    DataSet ds = new DataSet();
                    adp.Fill(ds, "GNM1styr_2014_15");
                    string passed = "";                    con.Close();
                    string[] Ones = { "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Ninteen" };
                    string[] Tens = { "Ten", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninty" };
                    
                   string num = ds.Tables[0].Rows[0]["sub_total"].ToString();
                    //int no = int.Parse(ds.Tables[0].Rows[0]["sub_total"].ToString());
                   int no = int.Parse(num);
                    string strWords = "";
                    if (no > 99 && no < 1000)                    {
                        int j = no / 100;
                        strWords = strWords + Ones[j - 1] + " Hundred ";
                        no = no % 100;                    }
                    if (no > 19 && no < 100)                    {
                        int j = no / 10;
                        strWords = strWords + Tens[j - 1] + " ";
                        no = no % 10;                    }
                    if (no > 0 && no < 20)                    {
                        strWords = strWords + Ones[no - 1];                    }
                    if (ds.Tables[0].Rows[0]["status"].ToString() == "PASS")
                    {                        passed = "and passed on";
                    }
                    else if (ds.Tables[0].Rows[0]["status"].ToString() == "FAIL")
                    {                        passed = "fail";
                    }                    else                    {
                        passed = "AB";                    }
                    Barcode("2014", ds.Tables[0].Rows[0]["roll_no"].ToString());
                    QrCode("2014", ds.Tables[0].Rows[0]["roll_no"].ToString());
                    string path = "http://www.onmeb.in/Images/barcode.png";
                    iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(new Uri(path));
                    image.ScaleAbsoluteHeight(50f);
                    image.ScaleAbsoluteWidth(100f);
                    string path1 = "http://www.onmeb.in/Images/qrcode.png";
                    iTextSharp.text.Image image1 = iTextSharp.text.Image.GetInstance(new Uri(path1));
                    image1.ScaleAbsoluteHeight(65f);
                    image1.ScaleAbsoluteWidth(65f);
                    string path2 = "http://www.onmeb.in/Images/Signature.jpg";
                    iTextSharp.text.Image image2 = iTextSharp.text.Image.GetInstance(new Uri(path2));
                    image2.ScaleAbsoluteHeight(30f);
                    image2.ScaleAbsoluteWidth(37f);
                    ///------Barcode table-------/////
                    PdfPTable p_bar = new PdfPTable(1);
                    p_bar.WidthPercentage = 85;
                    int[] farr_bar = new int[] { 100 };
                    p_bar.SetWidths(farr_bar);
                    PdfPCell[] pbarcell = new PdfPCell[] { new PdfPCell(new Phrase("", new Font(Font.HELVETICA, 10, Font.BOLD))) };
                    PdfPCell[] pbarcell1 = new PdfPCell[] { new PdfPCell(image) };
                    pbarcell[0].Border = 0;
                    pbarcell[0].HorizontalAlignment = Element.ALIGN_CENTER;
                    pbarcell1[0].Border = 0;
                    pbarcell1[0].HorizontalAlignment = Element.ALIGN_CENTER;
                    PdfPRow pbarpr = new PdfPRow(pbarcell);
                    PdfPRow pbarpr1 = new PdfPRow(pbarcell1);
                    p_bar.Rows.Add(pbarpr);
                    p_bar.Rows.Add(pbarpr1);
                    ///------Sign table-------/////
                    PdfPTable p_sign = new PdfPTable(1);
                    p_sign.WidthPercentage = 85;
                    int[] farr_sign = new int[] { 100 };
                    p_sign.SetWidths(farr_sign);
                    PdfPCell[] psigncell = new PdfPCell[] { new PdfPCell(image2) };
                    PdfPCell[] psigncell1 = new PdfPCell[] { new PdfPCell(new Phrase("\nSecretary\nODISHA NURSES & MIDWIVES\nEXAMINATION BOARD", new Font(Font.HELVETICA, 10, Font.BOLD))) };
                    psigncell[0].Border = 0;
                    psigncell[0].HorizontalAlignment = Element.ALIGN_CENTER;
                    psigncell1[0].Border = 0;
                    psigncell1[0].HorizontalAlignment = Element.ALIGN_CENTER;
                    PdfPRow psignpr = new PdfPRow(psigncell);
                    PdfPRow psignpr1 = new PdfPRow(psigncell1);
                    p_sign.Rows.Add(psignpr);
                    p_sign.Rows.Add(psignpr1);
                    ///-------------footer table---------////
                    PdfPTable p_img = new PdfPTable(3);
                    p_img.WidthPercentage = 85;
                    int[] farr_img = new int[] { 30, 20, 50 };
                    p_img.SetWidths(farr_img);
                    PdfPCell[] pimgcell = new PdfPCell[] { new PdfPCell(p_bar),   
                                            new PdfPCell(image1), 
                                            new PdfPCell(p_sign)};
                    PdfPCell[] pimgblank = new PdfPCell[] { new PdfPCell(new Phrase("\n",new Font(Font.HELVETICA,10))),   
                                            new PdfPCell(new Phrase("\n",new Font(Font.HELVETICA,10))), 
                                            new PdfPCell(new Phrase("\n",new Font(Font.HELVETICA,10)))};
                    pimgcell[0].Border = 0;
                    pimgcell[1].Border = 0;
                    pimgcell[2].Border = 0;
                    pimgblank[0].Border = 0;
                    pimgblank[1].Border = 0;
                    pimgblank[2].Border = 0;
                    pimgcell[1].HorizontalAlignment = Element.ALIGN_CENTER;
                    PdfPRow pimgpr = new PdfPRow(pimgcell);
                    PdfPRow pimgpr1 = new PdfPRow(pimgblank);
                    p_img.Rows.Add(pimgpr1);
                    p_img.Rows.Add(pimgpr);
                    p_img.Rows.Add(pimgpr1);
                    /////---------name table(2)-------------////
                    PdfPTable p71 = new PdfPTable(1);
                    p71.WidthPercentage = 100;
                    int[] p71far = new int[] { 100 };
                    p71.SetWidths(p71far);
                    PdfPCell[] p71cell1 = new PdfPCell[] { new PdfPCell(new Phrase(ds.Tables[0].Rows[0]["s_name"].ToString().ToUpper(), new Font(Font.HELVETICA, 10))) };
                    p71cell1[0].BorderWidthLeft = 0f;
                    p71cell1[0].BorderWidthTop = 0f;
                    p71cell1[0].BorderWidthRight = 0f;
                    p71cell1[0].BorderWidthBottom = 1f;
                    p71cell1[0].HorizontalAlignment = Element.ALIGN_CENTER;
                    PdfPRow p71r = new PdfPRow(p71cell1);
                    p71.Rows.Add(p71r);
                    /////---------name table-------------////
                    PdfPTable p7 = new PdfPTable(3);
                    p7.WidthPercentage = 100;
                    int[] p7far = new int[] { 25, 72, 3 };
                    p7.SetWidths(p7far);
                    PdfPCell[] p7cell1 = new PdfPCell[] { new PdfPCell(new Phrase(" To,  Smt/Shri. ",new Font(Font.HELVETICA,10))),                                               
                                            new PdfPCell(p71),
                                            new PdfPCell(new Phrase("",new Font(Font.HELVETICA,10)))};
                    p7cell1[0].Border = 0;
                    p7cell1[1].Border = 0;
                    p7cell1[2].Border = 0;
                    PdfPRow p7r = new PdfPRow(p7cell1);
                    p7.Rows.Add(p7r);
                    /////---------college_name table(2)-------------////
                    PdfPTable p81 = new PdfPTable(1);
                    p81.WidthPercentage = 100;
                    int[] p81far = new int[] { 100 };
                    p81.SetWidths(p81far);
                    PdfPCell[] p81cell1 = new PdfPCell[] { new PdfPCell(new Phrase(ds.Tables[0].Rows[0]["i_name"].ToString(), new Font(Font.HELVETICA, 10))) };
                    p81cell1[0].BorderWidthLeft = 0f;
                    p81cell1[0].BorderWidthTop = 0f;
                    p81cell1[0].BorderWidthRight = 0f;
                    p81cell1[0].BorderWidthBottom = 1f;
                    p81cell1[0].HorizontalAlignment = Element.ALIGN_CENTER;
                    PdfPRow p81r = new PdfPRow(p81cell1);
                    p81.Rows.Add(p81r);
                    /////---------college_name table-------------////
                    PdfPTable p8 = new PdfPTable(3);
                    p8.WidthPercentage = 100;
                    int[] p8far = new int[] { 25, 72, 3 };
                    p8.SetWidths(p8far);
                    PdfPCell[] p8cell1 = new PdfPCell[] { new PdfPCell(new Phrase(" School of Nursing ",new Font(Font.HELVETICA,10))),                                               
                                            new PdfPCell(p81),
                                            new PdfPCell(new Phrase("",new Font(Font.HELVETICA,10)))};
                    p8cell1[0].Border = 0;
                    p8cell1[1].Border = 0;
                    p8cell1[1].HorizontalAlignment = Element.ALIGN_CENTER;
                    p8cell1[2].Border = 0;
                    PdfPRow p8r = new PdfPRow(p8cell1);
                    p8.Rows.Add(p8r);
                    /////---------roll_no table(2)-------------////
                    PdfPTable p91 = new PdfPTable(1);
                    p91.WidthPercentage = 100;
                    int[] p91far = new int[] { 100 };
                    p91.SetWidths(p91far);
                    PdfPCell[] p91cell1 = new PdfPCell[] { new PdfPCell(new Phrase(ds.Tables[0].Rows[0]["roll_no"].ToString(), new Font(Font.HELVETICA, 10))) };
                    p91cell1[0].BorderWidthLeft = 0f;
                    p91cell1[0].BorderWidthTop = 0f;
                    p91cell1[0].BorderWidthRight = 0f;
                    p91cell1[0].BorderWidthBottom = 1f;
                    p91cell1[0].HorizontalAlignment = Element.ALIGN_CENTER;
                    PdfPRow p91r = new PdfPRow(p91cell1);
                    p91.Rows.Add(p91r);
                    /////---------roll_no table-------------////
                    PdfPTable p9 = new PdfPTable(3);
                    p9.WidthPercentage = 100;
                    int[] p9far = new int[] { 10, 10, 80 };
                    p9.SetWidths(p9far);
                    PdfPCell[] p9cell1 = new PdfPCell[] { new PdfPCell(new Phrase(" Roll No.",new Font(Font.HELVETICA,10))),                                               
                                            new PdfPCell(p91),
                                            new PdfPCell(new Phrase("The following marks were awarded to him/her at the FIRST Year G.N.M.Examination",new Font(Font.HELVETICA,10)))};
                    p9cell1[0].Border = 0;
                    p9cell1[1].Border = 0;
                    p9cell1[1].HorizontalAlignment = Element.ALIGN_CENTER;
                    p9cell1[2].Border = 0;
                    PdfPRow p9r = new PdfPRow(p9cell1);
                    p9.Rows.Add(p9r);
                    /////---------passed_in table(2)-------------////
                    PdfPTable p102 = new PdfPTable(1);
                    p102.WidthPercentage = 100;
                    int[] p102far = new int[] { 100 };
                    p102.SetWidths(p102far);
                    PdfPCell[] p102cell1 = new PdfPCell[] { new PdfPCell(new Phrase("03.03.2014", new Font(Font.HELVETICA, 10))) };
                    p102cell1[0].BorderWidthLeft = 0f;
                    p102cell1[0].BorderWidthTop = 0f;
                    p102cell1[0].BorderWidthRight = 0f;
                    p102cell1[0].BorderWidthBottom = 1f;
                    p102cell1[0].HorizontalAlignment = Element.ALIGN_CENTER;
                    PdfPRow p102r = new PdfPRow(p102cell1);
                    p102.Rows.Add(p102r);
                    /////---------passed_in table(1)-------------////
                    PdfPTable p101 = new PdfPTable(1);
                    p101.WidthPercentage = 100;
                    int[] p101far = new int[] { 100 };
                    p101.SetWidths(p101far);
                    PdfPCell[] p101cell1 = new PdfPCell[] { new PdfPCell(new Phrase("Dec-2013", new Font(Font.HELVETICA, 10))) };
                    p101cell1[0].BorderWidthLeft = 0f;
                    p101cell1[0].BorderWidthTop = 0f;
                    p101cell1[0].BorderWidthRight = 0f;
                    p101cell1[0].BorderWidthBottom = 1f;
                    p101cell1[0].HorizontalAlignment = Element.ALIGN_CENTER;
                    PdfPRow p101r = new PdfPRow(p101cell1);
                    p101.Rows.Add(p101r);
                    /////---------passed_in table-------------////
                    PdfPTable p10 = new PdfPTable(5);
                    p10.WidthPercentage = 100;
                    int[] p10far = new int[] { 10, 15, 15, 15, 45 };
                    p10.SetWidths(p10far);
                    PdfPCell[] p10cell1 = new PdfPCell[] { new PdfPCell(new Phrase(" held in ",new Font(Font.HELVETICA,10))),                                               
                                            new PdfPCell(p101),  
                                            new PdfPCell(new Phrase(passed,new Font(Font.HELVETICA,10))),                                               
                                            new PdfPCell(p102),                                               
                                            new PdfPCell(new Phrase("",new Font(Font.HELVETICA,10)))};
                    p10cell1[0].Border = 0;
                    p10cell1[1].Border = 0;
                    p10cell1[2].Border = 0;
                    p10cell1[3].Border = 0;
                    p10cell1[4].Border = 0;
                    PdfPRow p10r = new PdfPRow(p10cell1);
                    p10.Rows.Add(p10r);
                    /////-----------header table--------////////
                    PdfPTable ph = new PdfPTable(1);
                    ph.WidthPercentage = 85;
                    int[] farrh = new int[] { 100 };
                    ph.SetWidths(farrh);
                    PdfPCell[] phce = new PdfPCell[] { new PdfPCell(new Phrase("\n", new Font(Font.HELVETICA, 10, Font.BOLD))) };
                    PdfPCell[] phc = new PdfPCell[] { new PdfPCell(new Phrase("\n", new Font(Font.HELVETICA, 10, Font.BOLD))) };
                    PdfPCell[] phcell = new PdfPCell[] { new PdfPCell(new Phrase("\nODISHA NURSES AND MIDWIVES EXAMINATION BOARD, BHUBANESWAR\n\n", new Font(Font.HELVETICA, 14, Font.BOLD))) };
                    PdfPCell[] phcell1 = new PdfPCell[] { new PdfPCell(new Phrase("MARKSHEET\n", new Font(Font.HELVETICA, 16, Font.BOLD))) };
                    PdfPCell[] phcell2 = new PdfPCell[] { new PdfPCell(new Phrase("************************************************\n\n", new Font(Font.HELVETICA, 10, Font.BOLD))) };
                    PdfPCell[] phcell3 = new PdfPCell[] { new PdfPCell(p7) };
                    PdfPCell[] phcell4 = new PdfPCell[] { new PdfPCell(p8) };
                    PdfPCell[] phcell5 = new PdfPCell[] { new PdfPCell(p9) };
                    PdfPCell[] phcell6 = new PdfPCell[] { new PdfPCell(p10) };
                    PdfPCell[] phcell7 = new PdfPCell[] { new PdfPCell(new Phrase("\n", new Font(Font.HELVETICA, 10, Font.BOLD))) };
                    PdfPCell[] phcell8 = new PdfPCell[] { new PdfPCell(new Phrase(" The subject in which the candidate was examined and marks awarded are as under.\n\n", new Font(Font.HELVETICA, 10))) };
                    phcell[0].Border = 0;
                    phcell[0].HorizontalAlignment = Element.ALIGN_CENTER;
                    phcell1[0].Border = 0;
                    phcell1[0].HorizontalAlignment = Element.ALIGN_CENTER;
                    phcell2[0].Border = 0;
                    phcell2[0].HorizontalAlignment = Element.ALIGN_CENTER;
                    phcell3[0].Border = 0;
                    phcell4[0].Border = 0;
                    phcell5[0].Border = 0;
                    phcell6[0].Border = 0;
                    phcell7[0].Border = 0;
                    phcell8[0].Border = 0;                    phc[0].Border = 0;
                    phce[0].Border = 0;                    
                    PdfPRow phpr = new PdfPRow(phcell);
                    PdfPRow phpr1 = new PdfPRow(phcell1);
                    PdfPRow phpr2 = new PdfPRow(phcell2);
                    PdfPRow phpr3 = new PdfPRow(phcell3);
                    PdfPRow phpr4 = new PdfPRow(phcell4);
                    PdfPRow phpr5 = new PdfPRow(phcell5);
                    PdfPRow phpr6 = new PdfPRow(phcell6);
                    PdfPRow phpr7 = new PdfPRow(phcell7);
                    PdfPRow phpr8 = new PdfPRow(phcell8);
                    PdfPRow phrc = new PdfPRow(phc);
                    PdfPRow phrce = new PdfPRow(phce);
                    ph.Rows.Add(phrc);                    ph.Rows.Add(phrce);
                    ph.Rows.Add(phpr);                    ph.Rows.Add(phpr1);
                    ph.Rows.Add(phpr2);                    ph.Rows.Add(phpr3);
                    ph.Rows.Add(phpr7);                    ph.Rows.Add(phpr4);
                    ph.Rows.Add(phpr7);                    ph.Rows.Add(phpr5);
                    ph.Rows.Add(phpr7);                    ph.Rows.Add(phpr6);
                    ph.Rows.Add(phpr7);                    ph.Rows.Add(phpr8);
                                        ///////////////////////////
                    PdfPTable p = new PdfPTable(5);
                    p.WidthPercentage = 85;
                    int[] farr = new int[] { 10, 35, 20, 15, 20 };
                    p.SetWidths(farr);
                    PdfPCell[] pcellh = new PdfPCell[] { new PdfPCell(ph),   
                                            new PdfPCell(), 
                                            new PdfPCell(),                                                        
                                            new PdfPCell(),
                                            new PdfPCell()};
                    PdfPCell[] pcell = new PdfPCell[] { new PdfPCell(new Phrase("Paper",new Font(Font.HELVETICA,10))),   
                                            new PdfPCell(new Phrase("Subject",new Font(Font.HELVETICA,10))), 
                                            new PdfPCell(new Phrase("Maximum \nMarks",new Font(Font.HELVETICA,10))),                                                        
                                            new PdfPCell(new Phrase("Pass\nMarks",new Font(Font.HELVETICA,10))),
                                            new PdfPCell(new Phrase("Marks\nAwarded",new Font(Font.HELVETICA,10)))};
                    PdfPCell[] pcell1 = new PdfPCell[] { new PdfPCell(new Phrase("\n\nI",new Font(Font.HELVETICA,10))),   
                                            new PdfPCell(new Phrase("\nTheory\nBio-Science\nAnatomy and Physiology\nMicrobiology\n\n",new Font(Font.HELVETICA,10))), 
                                            new PdfPCell(new Phrase("\n\n100",new Font(Font.HELVETICA,10))),                                                        
                                            new PdfPCell(new Phrase("\n\n50",new Font(Font.HELVETICA,10))),
                                            new PdfPCell(new Phrase("\n\n"+ds.Tables[0].Rows[0]["tp1_t"].ToString(),new Font(Font.HELVETICA,10)))};
                    PdfPCell[] pcell2 = new PdfPCell[] { new PdfPCell(new Phrase("\n\nII",new Font(Font.HELVETICA,10))),   
                                            new PdfPCell(new Phrase("\nTheory\nBehavioral - Science\nPsychology\nSociology\n\n",new Font(Font.HELVETICA,10))), 
                                            new PdfPCell(new Phrase("\n\n100",new Font(Font.HELVETICA,10))),                                                        
                                            new PdfPCell(new Phrase("\n\n50",new Font(Font.HELVETICA,10))),
                                            new PdfPCell(new Phrase("\n\n"+ds.Tables[0].Rows[0]["tp2_t"].ToString(),new Font(Font.HELVETICA,10)))};
                    PdfPCell[] pcell3 = new PdfPCell[] { new PdfPCell(new Phrase("\n\nIII",new Font(Font.HELVETICA,10))),   
                                            new PdfPCell(new Phrase("\nTheory\nFundamental of Nursing.\nFirst Aid.\nPersonal Hygiene.\n\n",new Font(Font.HELVETICA,10))), 
                                            new PdfPCell(new Phrase("\n\n100",new Font(Font.HELVETICA,10))),                                                        
                                            new PdfPCell(new Phrase("\n\n50",new Font(Font.HELVETICA,10))),
                                            new PdfPCell(new Phrase("\n\n"+ds.Tables[0].Rows[0]["tp3_t"].ToString(),new Font(Font.HELVETICA,10)))};
                    PdfPCell[] pcell4 = new PdfPCell[] { new PdfPCell(new Phrase("",new Font(Font.HELVETICA,10))),   
                                            new PdfPCell(new Phrase("\nPractical - I\nFundamental of Nursing\n\n",new Font(Font.HELVETICA,10))), 
                                            new PdfPCell(new Phrase("\n100",new Font(Font.HELVETICA,10))),                                                        
                                            new PdfPCell(new Phrase("\n50",new Font(Font.HELVETICA,10))),
                                            new PdfPCell(new Phrase("\n"+ds.Tables[0].Rows[0]["pr1_t"].ToString(),new Font(Font.HELVETICA,10)))};
                    PdfPCell[] pcell5 = new PdfPCell[] { new PdfPCell(new Phrase("\n\n\n\nIV",new Font(Font.HELVETICA,10))),   
                                            new PdfPCell(new Phrase("\nTheory\nCommunity Health Nursing - I\nCommunity Health Nursing.\nEnvironmental Hygiene.\nHealth Education and\nCommunication Skills.\nNutrition\n\n",new Font(Font.HELVETICA,10))), 
                                            new PdfPCell(new Phrase("\n\n\n\n100",new Font(Font.HELVETICA,10))),                                                        
                                            new PdfPCell(new Phrase("\n\n\n\n50",new Font(Font.HELVETICA,10))),
                                            new PdfPCell(new Phrase("\n\n\n\n"+ds.Tables[0].Rows[0]["tp4_t"].ToString(),new Font(Font.HELVETICA,10)))};
                    PdfPCell[] pcell6 = new PdfPCell[] { new PdfPCell(new Phrase("",new Font(Font.HELVETICA,10))),   
                                            new PdfPCell(new Phrase("\nTotal Marks\n\n",new Font(Font.HELVETICA,10))), 
                                            new PdfPCell(new Phrase("\n500\n\n",new Font(Font.HELVETICA,10))),                                                        
                                            new PdfPCell(new Phrase("\n250\n\n",new Font(Font.HELVETICA,10))),
                                            new PdfPCell(new Phrase("\n"+ds.Tables[0].Rows[0]["sub_total"].ToString()+"\n\n",new Font(Font.HELVETICA,10)))};
                    PdfPCell[] pcell7 = new PdfPCell[] { new PdfPCell(new Phrase("\nIN WORDS : "+strWords+"\n\n",new Font(Font.HELVETICA,10))),   
                                            new PdfPCell(new Phrase("",new Font(Font.HELVETICA,10))), 
                                            new PdfPCell(new Phrase("",new Font(Font.HELVETICA,10))),                                                        
                                            new PdfPCell(new Phrase("",new Font(Font.HELVETICA,10))),
                                            new PdfPCell(new Phrase("",new Font(Font.HELVETICA,10)))};
                    PdfPCell[] pcell8 = new PdfPCell[] { new PdfPCell(p_img),   
                                            new PdfPCell(), 
                                            new PdfPCell(),                                                         
                                            new PdfPCell(), 
                                            new PdfPCell()};
                    pcellh[0].Colspan = 5;
                    pcell[0].HorizontalAlignment = Element.ALIGN_CENTER;
                    pcell[2].HorizontalAlignment = Element.ALIGN_CENTER;
                    pcell[3].HorizontalAlignment = Element.ALIGN_CENTER;
                    pcell[4].HorizontalAlignment = Element.ALIGN_CENTER;
                    pcell1[0].HorizontalAlignment = Element.ALIGN_CENTER;
                    pcell1[2].HorizontalAlignment = Element.ALIGN_CENTER;
                    pcell1[3].HorizontalAlignment = Element.ALIGN_CENTER;
                    pcell1[4].HorizontalAlignment = Element.ALIGN_CENTER;
                    pcell2[0].HorizontalAlignment = Element.ALIGN_CENTER;
                    pcell2[2].HorizontalAlignment = Element.ALIGN_CENTER;
                    pcell2[3].HorizontalAlignment = Element.ALIGN_CENTER;
                    pcell2[4].HorizontalAlignment = Element.ALIGN_CENTER;
                    pcell3[0].HorizontalAlignment = Element.ALIGN_CENTER;
                    pcell3[2].HorizontalAlignment = Element.ALIGN_CENTER;
                    pcell3[3].HorizontalAlignment = Element.ALIGN_CENTER;
                    pcell3[4].HorizontalAlignment = Element.ALIGN_CENTER;
                    pcell4[0].HorizontalAlignment = Element.ALIGN_CENTER;
                    pcell4[2].HorizontalAlignment = Element.ALIGN_CENTER;
                    pcell4[3].HorizontalAlignment = Element.ALIGN_CENTER;
                    pcell4[4].HorizontalAlignment = Element.ALIGN_CENTER;
                    pcell5[0].HorizontalAlignment = Element.ALIGN_CENTER;
                    pcell5[2].HorizontalAlignment = Element.ALIGN_CENTER;
                    pcell5[3].HorizontalAlignment = Element.ALIGN_CENTER;
                    pcell5[4].HorizontalAlignment = Element.ALIGN_CENTER;
                    pcell6[0].HorizontalAlignment = Element.ALIGN_CENTER;
                    pcell6[2].HorizontalAlignment = Element.ALIGN_CENTER;
                    pcell6[3].HorizontalAlignment = Element.ALIGN_CENTER;
                    pcell6[4].HorizontalAlignment = Element.ALIGN_CENTER;
                    pcell7[0].HorizontalAlignment = Element.ALIGN_LEFT;
                    pcell7[0].Colspan = 5;
                    pcell8[0].Colspan = 5;
                    PdfPRow prh = new PdfPRow(pcellh);
                    PdfPRow pr = new PdfPRow(pcell);
                    PdfPRow pr1 = new PdfPRow(pcell1);
                    PdfPRow pr2 = new PdfPRow(pcell2);
                    PdfPRow pr3 = new PdfPRow(pcell3);
                    PdfPRow pr4 = new PdfPRow(pcell4);
                    PdfPRow pr5 = new PdfPRow(pcell5);
                    PdfPRow pr6 = new PdfPRow(pcell6);
                    PdfPRow pr7 = new PdfPRow(pcell7);
                    PdfPRow pr8 = new PdfPRow(pcell8);
                    p.Rows.Add(prh);                    p.Rows.Add(pr);
                    p.Rows.Add(pr1);                    p.Rows.Add(pr2);
                    p.Rows.Add(pr3);                    p.Rows.Add(pr4);
                    p.Rows.Add(pr5);                    p.Rows.Add(pr6);
                    p.Rows.Add(pr7);                    p.Rows.Add(pr8);
                    Doc.Add(p);                }            }
            Doc.Close();
            string Path = Server.MapPath("~/GNM/") + "//marksheet.pdf";
            ShowPdf(Path);        }  private void ShowPdf(string strS)    {
        Response.ClearContent();        Response.ClearHeaders();
        Response.ContentType = "application/pdf";
        Response.AddHeader("Content-Disposition", "attachment; filename=" + strS);
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.TransmitFile(strS);        Response.End();
        Response.Flush();        Response.Clear();    }

 

Posted on Mar 13, 2014 11:30 PM Modified on on Mar 14, 2014 05:09 AM

This marksheet.PDf is being opened somewhere and hence you get error.

And also you need to dispose the Document object by calling

Doc.Dispose();

Once the processing is done