Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I was wondering if CAML query Value Types are strongly typed or not. It would save me some time if I didn't have to specify "text" or "date" every time I made a query.

Here is the code I am using, its part of a helper method that allows me to grab an item based on a certain field and that field's value.

String camlQuery = "<Where><Eq><FieldRef Name ='" + internalFieldName + "' /><Value Type='" + fieldType + "'>" + fieldValue + "</Value></Eq></Where>

I would like to get rid of the if possible.

share|improve this question

1 Answer 1

You don't necessarily do but it is highly recomanded to do so when you know them (particularly for Lookup, User, Data) while filtering. Pasted more examples below for your reference.

<View>
   <ViewFields>
      <ProjectProperty Name="Title"      Nullable="TRUE" />
      <ProjectProperty Name="Url"        Nullable="TRUE" />
      <FieldRef Name="EncodedAbsUrl"     Nullable="TRUE" />
      <FieldRef Name="PublishingContact" Nullable="TRUE" />
      <FieldRef Name="Title"                             />
      <FieldRef Name="FileRef"                           />
      <FieldRef Name="Comments"                          />
      <FieldRef Name="ID"                                />
      <FieldRef Name="Modified"                          />
      <FieldRef Name="Created"                           />
      <FieldRef Name="PublishingRollupImage"             />
      <FieldRef Name="Author"                            />
      <FieldRef Name="Editor"                            />
   </ViewFields>
   <Query>
      <Where>
         <And>
            <Or>
               <BeginsWith>
                  <FieldRef Name="ContentTypeId" />
                  <Value Type="Text">0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39001bb192640f8748d78db60217bd43598900f8c9db8d7f634c95bfd7ee95032f71c2</Value>
               </BeginsWith>
               <BeginsWith>
                  <FieldRef Name="ContentTypeId" />
                  <Value Type="Text">0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39001bb192640f8748d78db60217bd435989004896ce0317db45a9ae9e840754b48672</Value>
               </BeginsWith>
            </Or>
            <Eq>
               <FieldRef Name="_ModerationStatus" />
               <Value Type="ModStat">Approved</Value>
            </Eq>
         </And>
      </Where>
      <OrderBy>
         <FieldRef Name="Modified" Ascending="FALSE" />
      </OrderBy>
   </Query>
   <RowLimit>10</RowLimit>
</View>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.