Ref:
HTML
<asp:Button ID="btnViewXML" runat="server" Text="View XML" OnClick="ViewXML" />
Namespace
Imports System.Data.SqlClient
Imports System.Data
VB.Net
Private Sub PopulateXML()
Dim constr As String = ConfigurationManager.ConnectionStrings("conString").ConnectionString
Using conn As New SqlConnection(constr)
Using cmd As New SqlCommand("SELECT * FROM Employees", conn)
Using da As New SqlDataAdapter(cmd)
Dim ds As New DataSet("EmployeesXML")
da.Fill(ds, "Employees")
ds.Tables("Employees").WriteXml(Server.MapPath("~/XML/Employees.xml"))
End Using
End Using
End Using
End Sub
Protected Sub ViewXML(sender As Object, e As EventArgs) Handles btnViewXML.Click
Me.PopulateXML()
Response.Clear()
Response.Buffer = True
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "application/xml"
Response.WriteFile(Server.MapPath("~/XML/Employees.xml"))
Response.Flush()
Response.[End]()
End Sub
Screenshot
