Hi All,

Presently I am browsing to a folder which contains xml files. futher i do validation against xsd.
But now I have to do some thing like this: When i select say folder1 in the subfolder1, subfolder2 and so on. these subfolders contains xml file which i have to validate against xsd. How do my code select files from subfolders and futher validation?

My code:

VB Code:
  1. Private Sub btnInputXMLFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInputXMLFile.Click
  2.  Dim foldername As String
  3.             Dim filename As String
  4.             If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
  5.                 foldername = FolderBrowserDialog1.SelectedPath()
  6.             Else
  7.                 Dim Results As DialogResult = FolderBrowserDialog1.ShowDialog
  8.                 If Results = DialogResult.Cancel Then
  9.                     Return
  10.                 End If
  11.                 Exit Sub
  12.             End If
  13.             mstrFolderXMLFiles = FolderBrowserDialog1.SelectedPath()
  14.             txtInputXMLFile.Text = foldername
  15.         End If
  16.                 validatexmls(mstrFolderXMLFiles)
  17. End sub
  18. Private Function validatexmls(ByVal infile As String) As Boolean
  19.         Dim filename As String
  20.  
  21.         Dim mydir As New DirectoryInfo(infile)
  22.         Dim m_xmld As XmlDocument
  23.  
  24.         Dim f As FileInfo() = mydir.GetFiles("*.xml")
  25.         Dim i, j As Integer
  26.         Try
  27.             If RadioButton2.Checked Then
  28.  
  29.                 For i = 0 To f.Length - 1
  30.                     filename = f(i).FullName
  31.                     ' create xml doc
  32.                     m_xmld = New XmlDocument
  33.                     m_xmld.Load(filename)
  34.  
  35.                     'First we create the xmltextreader
  36.                     Dim xmlr As New XmlTextReader(filename)
  37.                     Dim sc As XmlSchemaCollection = New XmlSchemaCollection
  38.                     AddHandler sc.ValidationEventHandler, AddressOf ValidationCallBack
  39.                     sc.Add(Nothing, mstrInputXSDFile.Trim)
  40.                     'We pass the xmltextreader into the xmlvalidatingreader
  41.                     'This will validate the xml doc with the schema file
  42.                     'NOTE the xml file it self points to the schema file
  43.                     Dim xmlvread As New XmlValidatingReader(xmlr)
  44.                     xmlvread.ValidationType = ValidationType.Schema
  45.                     xmlvread.Schemas.Add(sc)
  46.                     ' Set the validation event handler
  47.                     AddHandler xmlvread.ValidationEventHandler, AddressOf ValidationCallBack
  48.                     m_success = True 'make sure to reset the success var
  49.  
  50.                     ' Read XML data
  51.                     While (xmlvread.Read)
  52.                     End While
  53.                     'Close the reader.
  54.                     xmlvread.Close()
  55.                 Next
  56.                 If m_success Then
  57.                     WriterBox.Text = "No Validation Errors"
  58.                 Else
  59.                     MsgBox("Validation Errors")
  60.                 End If
  61.             End If
  62.  
  63.         Catch a As UnauthorizedAccessException
  64.             'dont have access permission
  65.             m_success = a.Message
  66.         Catch a As Exception
  67.             'and other things that could go wrong
  68.             m_success = a.Message
  69.         End Try
  70.         'The validationeventhandler is the only thing that would
  71.         'set m_Success to false
  72.         Return m_success
  73.     End Function