How to import /export database data from /to csv/XML/excel using ASP.NET and C#.
for complate example visit:
http://dotnetawesome.blogspot.com/2013/11/how-to-import-export-database-data-from_16.html
protected void btnExport_Click(object sender, EventArgs e)
{
using (MuDatabaseEntities dc = new MuDatabaseEntities())
{
List<EmployeeMaster> emList = dc.EmployeeMasters.ToList();
if (emList.Count > 0)
{
var xEle = new XElement("Employees",
from emp in emList
select new XElement("Employee",
new XElement("EmployeeID", emp.EmployeeID),
new XElement("CompanyName", emp.CompanyName),
new XElement("ContactName", emp.ContactName),
new XElement("ContactTitle", emp.ContactTitle),
new XElement("EmployeeAddress", emp.EmployeeAddress),
new XElement("PostalCode", emp.PostalCode)
));
HttpContext context = HttpContext.Current;
context.Response.Write(xEle);
context.Response.ContentType = "application/xml";
context.Response.AppendHeader("Content-Disposition", "attachment; filename=EmployeeData.xml");
context.Response.End();
}
}
}