ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Exporting ASP.Net Repeater using iTextSharp Error: The Uri string is too long<p>Hi <a class="username" rel="Tevin"> Tevin</a>,</p> <p>Refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;asp:Panel ID=&#34;PanelEmployeeMedicalHistory&#34; CssClass=&#34;panel panel-default absolutePrintElement&#34; Enabled=&#34;true&#34; runat=&#34;server&#34;&gt; &lt;div class=&#34;panel-heading&#34; style=&#34;text-align: center;&#34;&gt; Employee Medical History&lt;/div&gt; &lt;div class=&#34;panel-body&#34;&gt; &lt;div class=&#34;form-row&#34;&gt; &lt;div class=&#34;col&#34;&gt; &lt;/div&gt; &lt;div class=&#34;col&#34;&gt; &lt;img runat=&#34;server&#34; id=&#34;ImgLogo&#34; src=&#34;http://www.lumotech.co.za/images/img_who-we-are_logo.png&#34; style=&#34;width: 200px;&#34; /&gt; &lt;/div&gt; &lt;div class=&#34;col&#34;&gt; &lt;/div&gt; &lt;/div&gt; &lt;br /&gt; &lt;div class=&#34;form-row&#34;&gt; &lt;div class=&#34;col-3&#34;&gt; &lt;/div&gt; &lt;div class=&#34;col&#34;&gt; &lt;asp:Label ID=&#34;lblAddress&#34; runat=&#34;server&#34; Font-Bold=&#34;true&#34; ForeColor=&#34;#0099ff&#34; Text=&#34;Fitzpatrick St, Cape Road Industrial | Uitenhage | P.O.Box 277 | 6229 | 041 9953016&#34;&gt; &lt;/asp:Label&gt; &lt;/div&gt; &lt;div class=&#34;col-3&#34;&gt; &lt;/div&gt; &lt;/div&gt; &lt;hr /&gt; &lt;asp:Repeater ID=&#34;RepeaterEmployee&#34; runat=&#34;server&#34;&gt; &lt;ItemTemplate&gt; &lt;table id=&#34;Table1&#34; runat=&#34;server&#34; class=&#34;table table-default table-striped table-bordered table-condensed&#34;&gt; &lt;tr&gt; &lt;td colspan=&#34;2&#34; style=&#34;text-align: center;&#34;&gt; &lt;asp:Image ID=&#34;Image1&#34; runat=&#34;server&#34; ImageAlign=&#34;Middle&#34; ImageUrl=&#39;&lt;%# GetUrl(Eval(&#34;Photo&#34;).ToString()) %&gt;&#39; /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td style=&#34;vertical-align: middle;&#34;&gt; &lt;/td&gt; &lt;td&gt; &lt;table id=&#34;Table2&#34; runat=&#34;server&#34; style=&#34;width: 100%;&#34;&gt; &lt;tr&gt; &lt;td&gt; &lt;b&gt;First Name:&lt;/b&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:Label ID=&#34;FirstName&#34; runat=&#34;server&#34; Text=&#39;&lt;%#Eval(&#34;FirstName&#34;) %&gt;&#39;&gt;&lt;/asp:Label&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;b&gt;Last Name:&lt;/b&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:Label ID=&#34;lblLastName&#34; runat=&#34;server&#34; Text=&#39;&lt;%#Eval(&#34;LastName&#34;) %&gt;&#39;&gt;&lt;/asp:Label&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;b&gt;Employee Code:&lt;/b&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:Label ID=&#34;lblCode&#34; runat=&#34;server&#34; Text=&#39;&lt;%#Eval(&#34;Code&#34;) %&gt;&#39;&gt;&lt;/asp:Label&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;b&gt;ID:&lt;/b&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:Label ID=&#34;lblEmployeeID&#34; runat=&#34;server&#34; Text=&#39;&lt;%#Eval(&#34;EmployeeID&#34;) %&gt;&#39;&gt;&lt;/asp:Label&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;b&gt;Cost Centre:&lt;/b&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:Label ID=&#34;lblCostCentre&#34; runat=&#34;server&#34; Text=&#39;&lt;%#Eval(&#34;CostCentre&#34;) %&gt;&#39;&gt;&lt;/asp:Label&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;b&gt;Medical Report:&lt;/b&gt; &lt;/td&gt; &lt;td&gt; &lt;asp:LinkButton ID=&#34;LinkButton1&#34; runat=&#34;server&#34; OnClick=&#34;LinkButton1_Click&#34; CommandName=&#34;download&#34;&gt;Download&lt;/asp:LinkButton&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/ItemTemplate&gt; &lt;/asp:Repeater&gt; &lt;/div&gt; &lt;/asp:Panel&gt;</pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Data; using System.IO; using iTextSharp.text.html.simpleparser; using iTextSharp.text; using iTextSharp.text.pdf;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Data Imports System.IO Imports iTextSharp.text Imports iTextSharp.text.html.simpleparser Imports iTextSharp.text.pdf</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { BindRepeater(); } } private void BindRepeater() { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[] { new DataColumn(&#34;Photo&#34;, typeof(string)), new DataColumn(&#34;FirstName&#34;, typeof(string)), new DataColumn(&#34;LastName&#34;, typeof(string)), new DataColumn(&#34;Code&#34;, typeof(string)), new DataColumn(&#34;EmployeeID&#34;, typeof(string)), new DataColumn(&#34;CostCentre&#34;, typeof(string)) }); dt.Rows.Add(&#34;ASPSnippetsLogo.png&#34;, &#34;Mudassar&#34;, &#34;Khan&#34;, &#34;c1&#34;, &#34;1&#34;, &#34;Mumbai&#34;); RepeaterEmployee.DataSource = dt; RepeaterEmployee.DataBind(); } protected void LinkButton1_Click(object sender, EventArgs e) { Response.ContentType = &#34;application/pdf&#34;; Response.AddHeader(&#34;content-disposition&#34;, &#34;attachment;filename=Panel.pdf&#34;); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); PanelEmployeeMedicalHistory.RenderControl(hw); StringReader sr = new StringReader(sw.ToString()); Document pdfDoc = new Document(PageSize.A4, 10.0F, 10.0F, 100.0F, 0.0F); HTMLWorker htmlparser = new HTMLWorker(pdfDoc); PdfWriter.GetInstance(pdfDoc, Response.OutputStream); Response.Write(pdfDoc); pdfDoc.Open(); htmlparser.Parse(sr); pdfDoc.Close(); Response.End(); } protected string GetUrl(string imagepath) { string[] splits = Request.Url.AbsoluteUri.Split(&#39;/&#39;); if (splits.Length &gt;= 2) { string url = splits[0] + &#34;//&#34;; for (int i = 2; i &lt; splits.Length - 1; i++) { url += splits[i]; url += &#34;/&#34;; } return url + imagepath; } return imagepath; } public override void VerifyRenderingInServerForm(Control control) { /* Verifies that the control is rendered */ }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Not Me.IsPostBack Then BindRepeater() End If End Sub Private Sub BindRepeater() Dim dt As DataTable = New DataTable() dt.Columns.AddRange(New DataColumn() {New DataColumn(&#34;Photo&#34;, GetType(String)), New DataColumn(&#34;FirstName&#34;, GetType(String)), New DataColumn(&#34;LastName&#34;, GetType(String)), New DataColumn(&#34;Code&#34;, GetType(String)), New DataColumn(&#34;EmployeeID&#34;, GetType(String)), New DataColumn(&#34;CostCentre&#34;, GetType(String))}) dt.Rows.Add(&#34;ASPSnippetsLogo.png&#34;, &#34;Mudassar&#34;, &#34;Khan&#34;, &#34;c1&#34;, &#34;1&#34;, &#34;Mumbai&#34;) RepeaterEmployee.DataSource = dt RepeaterEmployee.DataBind() End Sub Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As EventArgs) Response.ContentType = &#34;application/pdf&#34; Response.AddHeader(&#34;content-disposition&#34;, &#34;attachment;filename=Panel.pdf&#34;) Response.Cache.SetCacheability(HttpCacheability.NoCache) Dim sw As StringWriter = New StringWriter() Dim hw As HtmlTextWriter = New HtmlTextWriter(sw) PanelEmployeeMedicalHistory.RenderControl(hw) Dim sr As StringReader = New StringReader(sw.ToString()) Dim pdfDoc As Document = New Document(PageSize.A4, 10.0F, 10.0F, 100.0F, 0.0F) Dim htmlparser As HTMLWorker = New HTMLWorker(pdfDoc) PdfWriter.GetInstance(pdfDoc, Response.OutputStream) Response.Write(pdfDoc) pdfDoc.Open() htmlparser.Parse(sr) pdfDoc.Close() Response.End() End Sub Protected Function GetUrl(ByVal imagepath As String) As String Dim splits As String() = Request.Url.AbsoluteUri.Split(&#34;/&#34;c) If splits.Length &gt;= 2 Then Dim url As String = splits(0) &amp; &#34;//&#34; For i As Integer = 2 To splits.Length - 1 - 1 url += splits(i) url += &#34;/&#34; Next Return url &amp; imagepath End If Return imagepath End Function Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control) End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://i.imgur.com/SuvxYmc.gif" alt="" width="352" height="523" /></p>https://www.aspforums.net:443/Threads/148348/Exporting-ASPNet-Repeater-using-iTextSharp-Error-The-Uri-string-is-too-long/https://www.aspforums.net:443/Threads/148348/Exporting-ASPNet-Repeater-using-iTextSharp-Error-The-Uri-string-is-too-long/Wed, 26 Jun 2019 03:32:20 GMT