วันจันทร์ที่ 2 พฤษภาคม พ.ศ. 2554

VB.net การ Read & Write XML file (แบบset Config)

ในการพัฒนาโปรแกรม ด้วย windows Application ต้องมีการทำ config เกี่ยวกับ Database,username,password,key ที่ผ่านมาเราอาจจะเคยเห็น โปรแกรมที่เป็น Application ใช้ file .ini, .txt และ .xml ซึ่งการ Read & Write xml มีหลากหลายแบบ ผมมีตัวอย่างการ set xml อย่างง่ายมาฝากดังตัวอย่าง

<?xml version="1.0" encoding="utf-8" ?>
- <configuration>
<ServerName>xxx.xxx.xxx.xxx</ServerName>
<UserName>findvb</UserName>
<Password>1234</Password>
</configuration>


ขั้นตอนคือ เราจะต้องมี pathfile ของ xmlของเราก่อนโดยใน fuctionผมกำหนดไว้ที่
Private filename As String = Application.StartupPath & "\" & "dataconfig.xml"


View Code

ไม่มีความคิดเห็น: