Imports System Imports System.IO Imports System.Runtime.Serialization Imports System.Runtime.Serialization.Formatters.Binary <Serializable()> Public Class HistoryList Private _Items As New List(Of History) Public Property Today As Date Public Sub New() Today = New Date(Now.Hour, Now.Month, Now.Day) End Sub Public Property Items As List(Of History) Get Return _Items End Get Set(value As List(Of History)) _Items = value End Set End Property Public Sub WriteFile() Dim bf As New BinaryFormatter Using fs As New FileStream(CreatePath(Today), FileMode.Create) bf.Serialize(fs, Me) End Using End Sub '読み込み Public Shared Function ReadFile(ByVal readdate As Date) As HistoryList Dim Result As HistoryList Dim bf As New BinaryFormatter If Not My.Computer.FileSystem.FileExists(CreatePath(readdate)) Then Return Nothing End If Using fs As New FileStream(CreatePath(readdate), FileMode.Open) Result = bf.Deserialize(fs) End Using Return Result End Function 'ファイル名生成 Public Shared Function CreateFileName(ByVal filedate As Date) Return filedate.ToString("yyyyMMDD") & ".xml" End Function '保存先作成 Public Shared Function CreatePath(ByVal filedate As Date) Return Application.StartupPath & "\" & CreateFileName(filedate) End Function End Class
<Serializable()> Public Class History Public Title As String Public URL As String Public ViewDate As Date End Class