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

发布于 2025-01-06 04:17:29 字数 497 浏览 0 评论 0原文

我又被困住了。如果可以的话请帮忙。我真的很感激。

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

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

同样,我想加载最后一个 xml 文件并将其放入数据集中。我通常会编写这样的代码

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

但是我如何找到最后一个 xml 文件并读取它?

非常感谢xo。希望你们度过愉快的一天。

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.

    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

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扬花落满肩 2025-01-13 04:17:29
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
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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文