Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i have a form after submitting the form the values should be stored in an xml file.. how to do it..pls explain step by step..






Regards
Raju

What I have tried:

New to liferay
Posted
Updated 2-Aug-16 8:58am
v2
Comments
[no name] 2-Aug-16 7:36am    
Are you using ASP.NET?

 
Share this answer
 
Comments
Maciej Los 2-Aug-16 14:42pm    
5ed!
CPallini 2-Aug-16 14:51pm    
Thank you!
refer XmlSerializer Class (System.Xml.Serialization)[^] class

follow the steps
Create an entity with the properties in the form as
C#
public class MyEntity
   {
       public string Name { get; set; }
       public string Age { get; set; }
       public string Address { get; set; }
   }


the below code is for using Asp.net application, however the concept is same for mvc or window etc..
C#
protected void btnSave_Click(object sender, EventArgs e)
        {
            // create a folder 'xmlfiles' in the root directory
            string filePath = Server.MapPath("xmlfiles") + "//" +  "myfile.xml"; //  Path for the xml

            MyEntity entity = new MyEntity();
            // initalise the properties of the entity 
            entity.Name = txtName.Text;
            entity.Age = txtAge.Text;
            entity.Address = txtAddress.Text;
            // end 

            XmlSerializer xs = new XmlSerializer(typeof(MyEntity));
            TextWriter tw = new StreamWriter(filePath);
            xs.Serialize(tw, entity);
        }
 
Share this answer
 
Comments
Maciej Los 2-Aug-16 14:42pm    
5ed!
Karthik_Mahalingam 3-Aug-16 0:11am    
Thanks Maciej Los
 
Share this answer
 
Comments
Karthik_Mahalingam 3-Aug-16 0:11am    
5! for the links
Maciej Los 3-Aug-16 1:40am    
Thank you, Karthik

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900