Thursday, August 27, 2009

Get CAML Query for list view

If we have a list and through ui we have created a view with some filter condition for that list.Sometime we need same records using CAML query in our code.But there is no way to get CAML from a list view through UI.In following ways you can get CAML for a list view.

  1. save the list as a template

  2. download the stp

  3. rename as a cab

  4. extract the manifest.xml.Following are the outxml for this

    <?xml version="1.0" encoding="UTF-8" ?>
    <ListTemplate WebUrl="http://dip-srv:6666">
    <Details>
    <Files>
    <UserLists>
    <WebParts>
    </ListTemplate>


  5. explore <UserLists>

    <UserLists>
    <List Name="{...}" Title="...>
    <MetaData>
    <Views>
    <View>
    </Views>
    <Fields></Fields>
    <ContentTypes></ContentTypes>
    <Forms></Forms>
    <Security></Security>
    <Receivers></Receivers>
    </MetaData>
    </List>
    </UserLists>

  6. exlore ur view under <Views> tag and look for <Query> tag .this is ur CAML.

    <View Name="{...}" Type="HTML" DisplayName="..." ...>
    <ViewFields></ViewFields>
    <Query>
    <GroupBy ...></GroupBy ...>
    <Where></Where>
    ...
    </Query>
    ...
    </View>


No comments: