Solved

CAML Query with Contains not working

Posted on 2011-03-20
4
701 Views
Last Modified: 2012-05-11
I have a list called wraps with 12 items, no matter what I search using the following query, it always returns me the 12 items, so its not working correctly.

I debugged and the variable tag is OK.

  SPSite site = SPContext.Current.Site;
                // get the list
                SPList lstTagList = site.RootWeb.Lists.TryGetList("Wraps");
                if (lstTagList != null)
                {
                    // Try to find the item I want
                    SPQuery query = new SPQuery();
                    query.Query = "<Query><Where><Contains><FieldRef Name='Agenda_x0020_Tags' /><Value Type='Text'>" + tag + "</Value></Contains></Where></Query>";
                    SPListItemCollection foundItems = lstTagList.GetItems(query);
                    DataView dv = new DataView(foundItems.GetDataTable());
                    PagedDataSource page = new PagedDataSource();
                    page.AllowCustomPaging = true;
                    page.AllowPaging = true;
                    page.DataSource = dv;
                    page.PageSize = 10;
                   
                    WrapsRepeater.DataSource = page;
                    WrapsRepeater.DataBind();
0
Comment
Question by:LuisEstebanValencia
  • 2
4 Comments
 
LVL 5

Expert Comment

by:navdeepmadan
ID: 35178266
0
 
LVL 14

Accepted Solution

by:
KoenVosters earned 500 total points
ID: 35178417
navdeep maybe read the question?

Luis you are probably using the querybuilder of U2U. You need to remove the <query> tags from your query.
0
 

Author Closing Comment

by:LuisEstebanValencia
ID: 35179102
Navdeep didnt event read the question. He think that just pasting an url would give him the points, you did the homework.

Thank you
0
 
LVL 14

Expert Comment

by:KoenVosters
ID: 35179112
gl at m* ;-)
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Work Over Net is a new and very powerful collaboration product. With its new easy interface it is becoming very competitive to other similar products like webex and office interactive. WON 2010 have the standard business tools needed for multi-offic…
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question