如何加载最后的XML文件并放入数据集vb.net

时间:2022-08-24 16:19:34

I am stuck again. Please help if any of you can. I am really appreciate it.

我再次陷入困境。如果你们有人可以帮忙。我真的很感激。

I am creating XML files and load them back again. I use this following code to write xml to a folder. the code below will put date and time to the file name. and this code works fine.

我正在创建XML文件并再次加载它们。我使用以下代码将xml写入文件夹。下面的代码将日期和时间放在文件名中。这段代码工作正常。

    Dim filename As String = Server.MapPath("XML\" & SESSIONid & "_" & Replace(timenow, ":", "-") & ".xml")
    dSetPupil.WriteXml(filename, True)

Again, I want to load the last xml file back and put in a dataset. I normally write code like

我再次想要加载最后一个xml文件并放入数据集。我通常写代码

    Dim dSet as new DataSet = ReadXml(Server.MapPath("AAA.xml")

But how can i find the last xml file and read it ?

但是我怎样才能找到最后一个xml文件并阅读它?

Thanks xo much. Hope you guys having a nice day.

谢谢你。希望你们过得愉快。

1 个解决方案

#1


1  

Dim strLastXmlFileWritten As String = String.Empty

Dim lstFiles As List(Of IO.FileInfo) = New IO.DirectoryInfo(Server.MapPath("XML\")).GetFiles().ToList()

Dim dteCreated As Date = DateTime.MinValue

For Each objFile As IO.FileInfo In lstFiles

    If objFile.CreationTime > dteCreated AndAlso _
       objFile.Extension = ".xml" Then

        dteCreated = objFile.CreationTime
        strLastXmlFileWritten = objFile.FullName

    End If

Next

#1


1  

Dim strLastXmlFileWritten As String = String.Empty

Dim lstFiles As List(Of IO.FileInfo) = New IO.DirectoryInfo(Server.MapPath("XML\")).GetFiles().ToList()

Dim dteCreated As Date = DateTime.MinValue

For Each objFile As IO.FileInfo In lstFiles

    If objFile.CreationTime > dteCreated AndAlso _
       objFile.Extension = ".xml" Then

        dteCreated = objFile.CreationTime
        strLastXmlFileWritten = objFile.FullName

    End If

Next