C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » XML »

Add Birth Day Details in XML File


Posted Date: 12 Oct 2009    Resource Type: Code Snippets    Category: XML
Author: santoshMember Level: Silver    
Rating: 1 out of 5Points: 5



I am giving a very nice example of how to create a XML File and add Birth Day details in that XML File.

Imports System.Xml
Imports System.IO
Public Class frmAddBirthDay
Dim XMLPath As String = System.Configuration.ConfigurationManager.AppSettings("XMLPath") & "\" & "BirthDay.xml" 'Define XMLPath in app.config
Private Sub btnWriteXML_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWriteXML.Click
If File.Exists(XMLPath) Then
WriteXML()
Else
CreateXML()
End If
End Sub
Private Sub WriteXML()
If txtName.Text = "" Then
MessageBox.Show("Please Enter Name", "BIRTH DAY", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
Dim xmldoc As New Xml.XmlDocument
xmldoc.Load(XMLPath)
Dim node As XmlNode
node = xmldoc.CreateNode(XmlNodeType.Element, "BirthDay", "")
Dim Title As XmlNode = xmldoc.CreateElement("Name")
Dim Title1 As XmlNode = xmldoc.CreateElement("BirthDate", "")
Title.InnerText = txtName.Text
Title1.InnerText = dtpBirthDate.Text
node.AppendChild(Title)
node.AppendChild(Title1)
xmldoc.DocumentElement.AppendChild(node)
xmldoc.Save(XMLPath)
MessageBox.Show(txtName.Text & " '" & "Birth Day Added Sucessfully", "BIRTHDAY", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Sub btnCreateXML_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateXML.Click
CreateXML()
End Sub
Private Sub createNode(ByVal Name As String, ByVal BirthDay As String, ByVal writer As XmlTextWriter)
writer.WriteStartElement("BirthDayDetails")
writer.WriteStartElement("Name")
writer.WriteString(Name)
writer.WriteEndElement()
writer.WriteStartElement("BirthDay")
writer.WriteString(BirthDay)
writer.WriteEndElement()
'writer.WriteEndElement()
End Sub
Private Sub CreateXML()
If txtName.Text = "" Then
MessageBox.Show("Please Enter Name", "BIRTH DAY", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
Dim writer As New XmlTextWriter(XMLPath, System.Text.Encoding.UTF8)
writer.WriteStartDocument(True)
writer.Formatting = Formatting.Indented
writer.Indentation = 2
writer.WriteStartElement("BirthDays")
createNode(txtName.Text, dtpBirthDate.Text, writer)
writer.WriteEndElement()
writer.WriteEndDocument()
writer.Close()
End If
End Sub
Private Sub frmAddBirthDay_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If File.Exists(XMLPath) Then
btnWriteXML.Visible = True
btnCreateXML.Visible = False
Else
btnCreateXML.Visible = True
btnWriteXML.Visible = False
End If
End Sub
End Class

More Details plz Visit
http://santoshdotnetarena.blogspot.com/

Attachments

  • Add Birth Day Details in XML File (33828-12147-Add Birth Day Details in XML File.rar)

    For more details, visit http://santoshdotnetarena.blogspot.com/2009/09/write-birth-day-in-existing-in-xml.html



  • Responses


    No responses found. Be the first to respond and make money from revenue sharing program.

    Feedbacks      
    Popular Tags   What are tags ?   Search Tags  
    Sign In to add tags.
    Write Details in XML File  .  

    Post Feedback


    This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
    You must Sign In to post a response.
    Next Resource: XSLT Tranformation - Node to attributes
    Previous Resource: Bind XML to DataGrid
    Return to Discussion Resource Index
    Post New Resource
    Category: XML


    Post resources and earn money!
     
    More Resources



    dotNet Slackers

    About Us    Contact Us    Privacy Policy    Terms Of Use