i have this code, i want to implement it to asp.net and call a button function so that when you click on it, it will generate a PDF with the result of that id.
this is my code. I'm open for any help and ideas
thanks in advance
using System;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
public class Program
{
public static void Main()
{
string str = @"<?xml version='1.0'?>
<information>
<details>
<id>01</id>
<empname>qwer</empname>
<empid>001</empid>
<dept>Accounts</dept>
<date>2011-01-15 12:21:25</date>
</details>
<details>
<id>02</id>
<empname>jdfklgd</empname>
<empid>002</empid>
<dept>Finance</dept>
<date>2011-01-20 10:21:25</date>
</details>
</information>";
var str1 = XElement.Parse(str);
//Search ID
string searchID = "01";
//Get Result
var result = str1.Elements("details").Where(x => x.Element("id").Value.Equals(searchID)).ToList();
if(result.Count() > 0)
{
//Get Specific element value
string s = result[0].Elements("empname").FirstOrDefault().Value;
Console.WriteLine(s);
}
}
}
After parsing the XML element, you could use the DetailsView control or some Label control to display the result, then, using the
ITextsharp library to export the web page to PDF file.
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
15 Points
43 Posts
how can i print/generate the result in pdf using c#
Apr 19, 2017 02:52 PM|tandohtakyie|LINK
i have this code, i want to implement it to asp.net and call a button function so that when you click on it, it will generate a PDF with the result of that id.
this is my code. I'm open for any help and ideas
thanks in advance
All-Star
45489 Points
7008 Posts
Microsoft
Re: how can i print/generate the result in pdf using c#
Apr 20, 2017 05:26 AM|Zhi Lv - MSFT|LINK
Hi tandohtakyie,
I suggest you could refer to the following code:
After parsing the XML element, you could use the DetailsView control or some Label control to display the result, then, using the ITextsharp library to export the web page to PDF file.
Code as below:
<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeBehind="ExportToPDF.aspx.cs" Inherits="WebSample.General.ExportToPDF" %> <div> <table> <tr> <td>ID:</td> <td> <asp:Label ID="lblID" runat="server" Text=""></asp:Label> </td> </tr> <tr> <td>Name:</td> <td> <asp:Label ID="lblName" runat="server" Text=""></asp:Label> </td> </tr> </table> <asp:Button ID="btnExport" runat="server" Text="Export" OnClick="btnExport_Click" /> </div>
Code behind:
More details about export data to PDF, see:
https://www.aspsnippets.com/Articles/Export-ASPNet-Web-Page-with-images-to-PDF-using-ITextsharp.aspx
Best regards,
Dillion