Click here to Skip to main content
16,019,018 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
i have an error message:

An exception of type 'System.Net.WebException' occurred in System.dll but was not handled in user code

Additional information: Could not find a part of the path 'C:\IMAGES\Website-Traffic.jpg'.

aspx.cs code:

using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text.pdf;

public partial class PDFCONVERTER : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//Populate DataTable
DataTable dt = new DataTable();
dt.Columns.Add("Name");
dt.Columns.Add("Age");
dt.Columns.Add("City");
dt.Columns.Add("mailid");
dt.Rows.Add();
dt.Rows[0]["Name"] = "madhu";
dt.Rows[0]["Age"] = "27";
dt.Rows[0]["City"] = "Mumbai";
dt.Rows[0]["mailid"] = "madhu@gmail.com";

//Bind Datatable to Labels
lblName.Text = dt.Rows[0]["Name"].ToString();
lblAge.Text = dt.Rows[0]["Age"].ToString();
lblCity.Text = dt.Rows[0]["City"].ToString();
lblCountry.Text = dt.Rows[0]["mailid"].ToString();
}

}
protected void btnExport_Click(object sender, EventArgs e)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf");
Response.Cache.SetCacheability(HttpCacheability.Server);
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);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();

}
}

default.aspx code:
<body>
<form id="form1" runat="server">

<img src="IMAGES/Website-Traffic.jpg" />
<%--<img src = "http://www.aspsnippets.com/images/Blue/Logo.png" />
--%>

This is a test page


<asp:Panel ID="pnlPerson" runat="server">

<%--
--%>
Name: <asp:Label ID="lblName" runat="server">
Age: <asp:Label ID="lblAge" runat="server">
City: <asp:Label ID="lblCity" runat="server">
mailid: <asp:Label ID="lblCountry" runat="server">




<asp:Button ID="btnExport" runat="server" Text="Export" onclick="btnExport_Click" />

</form>
</body>
Posted
Comments
[no name] 28-Jan-16 3:47am    
It means when it is writing HTML content PDF file, it is searching the image file at "C:\IMAGES\Website-Traffic.jpg". Make sure that image is present at that location.

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