Wednesday, August 7, 2013

Dynamically Create CAML QUERY

 By using this code we can create a CAML Query at run time .
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
 Public Function topic_Wise_Collection(ByVal strin As ListItemCollection) As String
        Dim str As String = "<Where>"
        Dim firstLine As String = ""
        Dim starting As String = ""
        Dim midll As String = ""
        Dim i As Integer = 0
        For Each _item As ListItem In strin
            Dim _topic01 As String = _item.ToString
            If i = 0 Then
                firstLine += "<Or>"
                firstLine += "<Contains>"
                firstLine += "<FieldRef Name=" + "Topic0" + " />"
                firstLine += "<Value Type=" + "Text" + ">" + _topic01 + "</Value>"
                firstLine += "</Contains><Contains>"
                firstLine += "<FieldRef Name=" + "Topic0" + " />"
                firstLine += "<Value Type=" + "Text" + ">" + _topic01 + "</Value>"
                firstLine += "</Contains>"
                firstLine += "</Or>"
            Else
                Dim befor As String
                befor = "<Or><Contains><FieldRef Name=" + "Topic0" + " />"
                befor += "<Value Type=" + "Text" + ">" + _topic01 + "</Value>"
                befor += "</Contains>"
                midll = befor + midll
                firstLine += "</Or>"
            End If
            i = i + 1
        Next
        str += midll + firstLine + "</Where>"
        Return str
    End Function

No comments:

Post a Comment