那今天就是來分享如何寫一個 .XML 檔案吧!!
居裡貓今天就是分享之前講到的小程式的第二集,
先看一下程式的長相:
好的,寫一個 .XML 他又是長個什麼模樣,這就貼給大家看看:
它的內容大概就是長這個樣子,內容的長相是取決於各位的
有人喜歡有人不喜歡的意思~
程式碼就是大概長這個樣子~~請看~
--------------------------------------------------------------------------------------------------------------------------
- 'Button Contorl XML Write
- Private Sub Btn_WriteXML_Click(sender As Object, e As EventArgs) Handles Btn_WriteXML.Click
- 'Check watch event was raising
- If Watcher.watcher.EnableRaisingEvents = False Then
- Watcher.watcher.EnableRaisingEvents = True
- End If
- Copy_Delete_File.GetPath(TxB_Local.Text, TxB_Remote.Text, TxB_NAS.Text, TxB_FTP.Text, ChB_UploadFTP.Checked)
- FTPupload.Get_FTPinfo(TxB_FTPAddress.Text, TxB_FTPAccount.Text, Txb_FTPPassword.Text)
- '這邊 ____________________________________________________
- Dim wrXML As New XML
- wrXML.LocalPath = TxB_Local.Text
- wrXML.RemotePath = TxB_Remote.Text
- wrXML.NASPath = TxB_NAS.Text
- wrXML.FTPPath = TxB_FTP.Text
- wrXML.Data = "This is a Programming Practices " & Now.ToString
- wrXML.DateTime = Now.ToString
- If ChB_UploadFTP.Checked Then
- wrXML.CheckFTP = "Ture"
- Else
- wrXML.CheckFTP = "Flase"
- End If
- Dim objectStreamWriter As New StreamWriter(TxB_Local.Text + ("\Program Practices " & Now.ToString("_yyyyMMddHHmmss") & ".xml"))
- Dim xmlserialize As New XmlSerializer(wrXML.GetType)
- xmlserialize.Serialize(objectStreamWriter, wrXML)
- objectStreamWriter.Dispose()
- '到這邊___才是主要控制寫XML的部分其他皆是其他控制需要的部分_______
- 'Check backwork status
- 'If Not back.IsBusy = True Then
- ' back.RunWorkerAsync()
- 'End If
- Backwork.main()
- End Sub
- '--------我是分割線,上面是 Write XML 按鈕的部分,下面是使用 XML 用的 Class
- 'XML Class 的內容就是取決於各位的設計來寫了
- '要用什麼樣的方法String Integer 之類的自行變化嘗試
- 'About used XML setting info
- Public Class XML
- Private _LoaclPath As String
- Public Property LocalPath() As String
- Get
- Return _LoaclPath
- End Get
- Set(value As String)
- _LoaclPath = value
- End Set
- End Property
- Private _RemotePath As String
- Public Property RemotePath() As String
- Get
- Return _RemotePath
- End Get
- Set(value As String)
- _RemotePath = value
- End Set
- End Property
- Private _NASPath As String
- Public Property NASPath() As String
- Get
- Return _NASPath
- End Get
- Set(value As String)
- _NASPath = value
- End Set
- End Property
- Private _FTPPath As String
- Public Property FTPPath() As String
- Get
- Return _FTPPath
- End Get
- Set(value As String)
- _FTPPath = value
- End Set
- End Property
- Private _Data As String
- Public Property Data() As String
- Get
- Return _Data
- End Get
- Set(value As String)
- _Data = value
- End Set
- End Property
- Private _DateTime As String
- Public Property DateTime() As String
- Get
- Return _DateTime
- End Get
- Set(value As String)
- _DateTime = value
- End Set
- End Property
- Private _CheckFTP As String
- Public Property CheckFTP() As String
- Get
- Return _CheckFTP
- End Get
- Set(value As String)
- _CheckFTP = value
- End Set
- End Property
- Private _Loginfo As List(Of String)
- Public Property Loginfo() As List(Of String)
- Get
- Return _Loginfo
- End Get
- Set(value As List(Of String))
- _Loginfo = value
- End Set
- End Property
- End Class
------------------------------------------------------------------------------------------------------------------------
今天分享的寫 XML 資料,
主要的資料內容我們用 Class 的方法來做一個整理,
為什麼要這樣子呢,當然是取用會方便跟預防一些不可預期的錯誤!
(你想問會有什麼錯誤,居裡貓有遇過,忽然可以寫忽然不可以寫的問題)
分享就到這邊,希望大家會喜歡,其他的部分在之後會接著分享出來~
感謝各位先進的教學文~!
ps. 分享程式中有一些好像沒看到關聯的部分,就是剛好參在一起
底下就是這個
1. 上報 練習 _ 選擇資料夾
2. 上報 練習 _ 寫一個 .XML 資料
3. 上報 練習 _ 監控資料夾
4. 上報 練習 _ 複製檔案
5. 上報 練習 _ FTP Server 檔案上傳
6. 上報 練習 _ 上傳錯誤紀錄
7. 上報 練習 _ 使用 BackgroundWorker 再次上傳
8. 上報 練習 _ Log 紀錄
9. 上報 練習 _ 完整程式碼分享
沒有留言:
張貼留言