Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
i am working on file conversion of webpage to pdf using itextsharp tool...i have binded the company details in a repeater control from sqlserver 2005..and the images are loaded from the directory path....patricular company correponding images is loaded from the directory...the problem i am facing is , i couldnt get the image when i am converting the webpage to pdf....i enclose the coding ....please help me
/* BINDING deatils to repeater*/
protected void Page_Load(object sender, EventArgs e)
        {
            string _strName = string.Empty;
            _strName = "q";
            //_strName = Request.QueryString["_strName"];
            DataTable Print_Rep = new DataTable();
            clsCompanySearch objRep_Cls = new clsCompanySearch();
            Print_Rep = objRep_Cls.company_pdf(_strName);
            Rpt_Company.DataSource = Print_Rep;
            Rpt_Company.DataBind();

            //ConvertPageToPDF(Page);
            
         }




/* BINDING THE IMAGES FROM THE DIRECTORY */

protected void Rpt_Company_Search_no_tabs_ItemDataBound(object sender, RepeaterItemEventArgs e)
      {
          System.Web.UI.WebControls.Image img = (System.Web.UI.WebControls.Image)e.Item.FindControl("img_logo");
          Label lbl_memberno = (Label)e.Item.FindControl("lblmemberno");
          string memberno = lbl_memberno.Text.ToString().Trim();
          //string image = HttpContext.Current.Server.MapPath("~/_Images/Arab_Logos/") + memberno.ToString() + ".jpg";
          string image = HttpContext.Current.Server.MapPath("~/_Images/Arab_Logos/") + memberno.ToString() + ".jpg";

          if (File.Exists(image))
          {
              img.ImageUrl = "~/_Images/Arab_Logos/" + memberno.ToString() + ".jpg";
              img.Visible = true;
          }
          else
          {
              img.Visible = false;
          }
      }


/*CONVERSION OF PDF */

protected void btnPDF_Click(object sender, EventArgs e)
     {

         Response.ContentType = "application/pdf";
         Response.AddHeader("content-disposition", "attachment;filename=yamunaPage.pdf");
         Response.Cache.SetCacheability(HttpCacheability.NoCache);
         StringWriter sw = new StringWriter();
         HtmlTextWriter hw = new HtmlTextWriter(sw);
         this.Page.RenderControl(hw);
         StringReader sr = new StringReader(sw.ToString());
         Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
         HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
         PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
         string path = HttpContext.Current.Server.MapPath("~/_Images/Arab_Logos/");
         pdfDoc.Open();
        // FileStream fs = new FileStream("~/_Images/Arab_Logos/", FileMode.Create);
         var appDataPath=Server.MapPath("~/_Images/Arab_Logos/");
         htmlparser.Parse(sr);[GETTING ERROR IN THIS LINE]
         pdfDoc.Close();
         Response.Write(pdfDoc);
         Response.End();

     }


so while converting to pdf ...i am getting the error as
Could not find a part of the path 'C:\_Images\Arab_Logos\1002.jpg'.



PLEASE help me as soon as possible...please
Posted
Updated 20-Apr-12 17:47pm
v2
Comments
Sergey Alexandrovich Kryukov 27-May-15 15:40pm    
The path name looks weird. MapPath with "~/*" should give you the path relative to the root directory setup for your site. Is the site itself correctly setup? Is this really the server-side code working through ASP.NET?
Please use the debugger.
—SA

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