Problems with checking fieldnames


#1

Attached file contains mergefields. In a .aspx page a check is done to certify that the file contains one or more of the required fields with this code

Dim MyDocument As Aspose.Words.Document = New Aspose.Words.Document(FileNameToStore)

'b. opvragen van de velden die in het document worden gebruikt

Dim Fieldnames As String() = MyDocument.MailMerge.GetFieldNames()

'c. opvragen van de velden die in de selectie zitten

Dim ColumnNameList As String() = {"Client_naam", "Client_adres_straat", "internnr", "Client_adres_huisnummer", "Client_adres_pcd", "Client_adres_wpl", "Client_huisarts", "Client_geslacht","Client_emailbevestigingscode", "Client_geboortedatum"}

Dim Namefound As Boolean
Dim ArrIndex As Integer
Dim FieldnameIndex As Integer
For FieldnameIndex = 0 To Fieldnames.Length - 1

For ArrIndex = 0 To ColumnNameList.Length - 1
If Fieldnames(FieldnameIndex) = ColumnNameList(ArrIndex) Then
Namefound = True
Exit For
Else
Namefound = False
End If
If Namefound = False Then
Exit For
End If
Next
Next

If Namefound = False Then
Me.Label2.Text = "een of meer verplichte velden ontbreken"
Me.Label2.ForeColor = Color.Red
System.IO.File.Delete(FileNameToStore)
Me.Page.Session.Remove("uploadedfile")
Me.Label3.Text = "bestand is niet geaccepteerd"
Me.Label3.ForeColor = Color.Red
Else
Me.Label2.Text = "Bestand ok"
Me.Label2.ForeColor = Color.Green
Dim FilenameNewTemp As String = FileNameToStore
Dim FilenameNew As String
FilenameNew = Left(FilenameNewTemp, FilenameNewTemp.Length - 5) ' het .temp gedeelte erafhalen
MyDocument.Save(FilenameNew)
Session("uploadedfile") = FilenameNew
Me.Label3.Text = "bestand is opgeslagen"
Me.Label3.ForeColor = Color.Green
PathFile.Text = FilenameNew
End If
System.IO.File.Delete(FileNameToStore)

This code concludes that it cannot find all the mergefields. To my humble opinion it contains all the required fields. very strange. When you remove the last mergefield the file is considered as valid ...

What can you suggest?


#2

For FieldnameIndex = 0 To Fieldnames.Length - 1

For ArrIndex = 0 To ColumnNameList.Length - 1
If Fieldnames(FieldnameIndex) = ColumnNameList(ArrIndex) Then
Namefound = True
Exit For
Else
Namefound = False
End If

Next

If Namefound = false

exit for
Next

Is better ...


#3

So the latter version of the loop should work I guess… Just tested it here.