Home > Articles > .Net Framework Articles > How to create xml file through c# code using Linq.

How to create xml file through c# code using Linq.

by vikash kumar   on Jan 28, 2016   Category: .Net Framework  | Level: Intermediate  |  Views: 691    |  Points: 100   
Like this article? Bookmark and Share:
This article is for those who want to create xml file through c# code using linq.

First of all include the given namespace.

using System.Xml.Linq;


Write the given codes on button click event.

 XDocument doc=new XDocument(new XDeclaration("1.0","utf-8","yes"),
                new XElement("Employees",
                    new XElement("Employee",
                    new XAttribute("ID","EMP001"),
                    new XElement("Name","Vikash bajaj"),
                    new XElement("Gender","Male")
                    ))
                );
            doc.Save(@"C:\Users\User1\Documents\Visual Studio 2013\Projects\Toggle\WebApplication1/Employee.xml");

This will create a xml file in the specified location in save method.


Like this article? Bookmark and Share:

Most viewed Articles

User Comments


No response found, be the first to review this article.

Submit feedback about this article

Please sign in to post feedback

Latest Posts