Hi esolutions,
Check this example. Now please take its reference and correct your code.
HTML
<asp:TextBox runat="server" ID="txtId" />
<asp:Button Text="Generate XML" runat="server" OnClick="GenerateXML" />
Namespaces
C#
using System.Xml.Linq;
using System.IO;
VB.Net
Imports System.IO
Code
C#
protected void GenerateXML(object sender, EventArgs e)
{
string[] datas = File.ReadAllLines(Server.MapPath("~/Test.txt"));
XDocument doc = new XDocument();
doc.Add(new XElement("Employee", datas.Where(x => Convert.ToInt32(x) > Convert.ToInt32(txtId.Text.Trim())).Select(x => new XElement("Id", x))));
doc.Save(Server.MapPath("~/Employee.xml"));
}
VB.Net
Protected Sub GenerateXML(ByVal sender As Object, ByVal e As EventArgs)
Dim datas As String() = File.ReadAllLines(Server.MapPath("~/Test.txt"))
Dim doc As XDocument = New XDocument()
doc.Add(New XElement("Employee", datas.Where(Function(x) Convert.ToInt32(x) > Convert.ToInt32(txtId.Text.Trim())).[Select](Function(x) New XElement("Id", x))))
doc.Save(Server.MapPath("~/Employee.xml"))
End Sub
Text file content
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
Generated XML
<?xml version="1.0" encoding="utf-8"?>
<Employee>
<Id>10006</Id>
<Id>10007</Id>
<Id>10008</Id>
<Id>10009</Id>
<Id>10010</Id>
</Employee>