Last post Feb 17, 2012 10:38 AM by thutaaung
Feb 17, 2012 08:46 AM|thutaaung|LINK
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")
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.
Feb 17, 2012 08:56 AM|Mastan Oli|LINK
Place that file name in a state and get back like...
Session("filename") = Server.MapPath("XML\" & SESSIONid & "_" & Replace(timenow, ":", "-") & ".xml")
'get from session state
Dim dSet as new DataSet = ReadXml(Server.MapPath(Session("filename"))
Feb 17, 2012 09:07 AM|thutaaung|LINK
Thanks for reply , mastan oli,
I can't really get it from the session state. Basically, the user close down the website and then if they come back again, we have to load the last XML file they saved so.
Is there any way to do that ?
Feb 17, 2012 10:38 AM|thutaaung|LINK
Got a solution from some1.
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