0

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.

Laurence
  • 7,633
  • 21
  • 78
  • 129

1 Answers1

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
NoAlias
  • 9,218
  • 2
  • 27
  • 46
  • You are absolute genius NoAlias, I googled whole morning and couldn't find that out. thanks sooooo much. – Laurence Feb 17 '12 at 15:12
  • Thanks for the compliment. I'm glad that it helped. www.mdsn.com is a good resource for discovering the different namespaces and classes of the .Net framework. – NoAlias Feb 17 '12 at 15:24