1
votes

When i upload a new image using web part. It's not showing the latest image modified. I want to query a image that is latest modified by the time. Example i want the image to displayed by the latest time modified.

Below is my code.

 query.Query = @"<Query>
        <Where><Eq><FieldRef Name='Title' /><Value Type='Text'></Value></Eq>

          <And>
            <Leq>
             <FieldRef Name='Modified' />
              <Value IncludeTimeValue='True' Type='DateTime'> <Now /></Value>
             </Leq> 
          </And>
       </Where>


          <OrderBy>
        <FieldRef Name='Modified' Ascending='False'/>
          </OrderBy>

        </Query>";
2
can you share you complete CAML query ? This looks to be a partial one, maybe the issue lies there - Gautam Sheth
I have updated my full code - Suresh
The issue lies on when i want to re-upload an existing image. It should take the latest modified existing image by the modified time. - Suresh

2 Answers

1
votes

You can try the below query:

query.Query = @"        
        <OrderBy>
            <FieldRef Name='Modified' Ascending='FALSE' />
        </OrderBy>";
query.RowLimit = 1;     

Couple of things to note, you dont need <Query> tag. If you just want items based on their modified date, simply use the OrderBy. If you only want the latest image, just specify the row limit as 1 which will fetch you only the latest image.

0
votes

You should not have Value tag inside of OrderBy, your CAML should look like this:

<OrderBy><FieldRef Name='Modified' Ascending='False'/></OrderBy>