答案 0 :(得分:0)
我会在这里使用序列化,而不是将其存储在设置中。
您可以像这样创建一个WebsiteObject类:
<Serializable()>
Public Class WebsiteObject
Private name As string
Private url As String
Public Sub New()
' Leave fields empty.
End Sub
Public Sub New(ByVal webname As DataSet, ByVal theurl As String)
name = webname
url = theurl
End Sub
Public Property WebsiteName as string
Get
Return name
End Get
Set(ByVal value As string)
name = value
End Set
End Property
Public Property WebsiteURL As String
Get
Return url
End Get
Set(ByVal value As String)
url = value
End Set
End Property
End Class
然后使用以下功能序列化和反序列化您的网站列表:
Public Sub WriteToBinaryFile(serializationFile As String, List As List(Of WebsiteObject))
Using stream As Stream = File.Open(serializationFile, FileMode.Create)
Dim bformatter = New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
bformatter.Serialize(stream, List)
End Using
End Sub
Public Function ReadFromBinaryFile(serializationFile As String)
Using stream As Stream = File.Open(serializationFile, FileMode.Open)
Dim bformatter = New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
Dim websites As List(Of WebsiteObject) = DirectCast(bformatter.Deserialize(stream), List(Of FavoritesObject))
Return websites
End Using
End Function
要导入和导出您的网站列表,只需使用:
dim websitelist as new list(of WebsiteObject)
dim site as new WebsiteObject
site.WebsiteURL = "url here"
site.WebsiteName = "site name here"
websitelist.add(site)
'write website list to file
WriteToBinaryFile("filepathhere.bin", websitelist)
'read website list from file
dim newwebsitelist as list(of WebsiteObject)= ReadFromBinaryFile("samefilepathhere.bin")`