I need to create xml by reading the pdf file names from a location.I wrote code but cannt get the iterative child nodes.Please help me for the same
Sample file names : ABC_2345_P1.pdf ABC_2111_Q1.pdf ABC_1225_Q2.pdf
The Out XML should require like below :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Folder>
<PolicyFrom>ABC</PolicyFrom>
<Documents>
<Doc>
<DocGuid>2345</DocGuid>
<DocType>P1</DocType>
<DocName>ABC_2345_P1.pdf</DocName>
</Doc>
<Doc>
<DocGuid>2111</DocGuid>
<DocType>Q1</DocType>
<DocName>ABC_2111_Q1.pdf</DocName>
</Doc>
<Doc>
<DocGuid>1225</DocGuid>
<DocType>Q2</DocType>
<DocName>ABC_1225_Q2.pdf</DocName>
</Doc>
</Documents>
</Folder>
I wrote a code but it dont create iterative child nodes,Please help me to rectify:
For i As Integer = 1 To _NoOfFiles
'Dim FileNameSeq = _DocIssueDate & "_" & _DocTypeCode & "_" & _PolicyNo & "_" & _CompanyCode & "_" & _Case_id & "_" & _NoOfFiles & "_" & _FileNo & "_" & _PStartDate
Dim FileNameSeq = _PolicyFrom & "_" & _DocGuid & "_" & _DocType & "_" & _DocName
If File.Exists(_SOURCEPDFPATHWITHOUTFILE & "\" & FileNameSeq & ".pdf") Then
Dim FileLocation As DirectoryInfo = New DirectoryInfo("C:\Folder\Subfolder\Data\Input\")
Dim FileLoc As String = "C:\Folder\Subfolder\Data\Input\"
'Dim fi As FileInfo() = FileLocation.GetFiles(_DocIssueDate & "_" & _DocTypeCode & "_" & _PolicyNo & "_" & _CompanyCode & "_" & _Case_id & "_" & _NoOfFiles & "_" & i & "_" & _PStartDate & ".pdf")
For Each file As String In IO.Directory.GetFiles(_SOURCEPDFPATHWITHOUTFILE, "" _PolicyFrom & "_" & _DocGuid & "_" & _DocType & "_" & _DocName & ".pdf", IO.SearchOption.AllDirectories)
'The next line of code gets file names with extensions from searched directories and subdirectories
Dim fName As String = IO.Path.GetFileName(file)
Console.WriteLine(fName)
If i = 1 Then
Dim Firstfile As String = fName
Dim companyFile As XElement = New XElement("Folder",
New XElement("PolicyFrom", New Object() ,
New XElement("Doc",
New XElement("DocGuid", _SOURCEPDFPATH_FileName,
New XElement("DocType", _SOURCEPDFPATH_FileName,
New XElement("DocName", _SOURCEPDFPATH_FileName,
))))
})
})
)
companyFile.Save("D:\PDF_UPLD\" & _SOURCEPDFPATH_FileName & ".xml")
End If
'System.IO.File.Delete(FileLoc & fName)
Next
End If
Next
Else
Continue For
End If
Next