Questions tagged [spquery]

SPQuery represents a query in a SharePoint list view

SPQuery represents a query in a SharePoint list view. Collaborative Application Markup Language (CAML) can be used to define the query.

Example:

SPWeb oWebsiteRoot = SPContext.Current.Site.RootWeb
SPList oList = oWebsiteRoot.Lists["Tasks"];

SPQuery oQuery = new SPQuery();
oQuery.Query = "<Where><Eq><FieldRef Name='Status'/>" + 
               "<Value Type='Text'>Completed</Value></Eq></Where>";

SPListItemCollection collListItems = oList.GetItems(oQuery);

foreach (SPListItem oListItem in collListItems)
{
    Response.Write(SPEncode.HtmlEncode(oListItem["Title"].ToString()) + 
        "<BR>");
}

MSDN - SPQuery

39 questions
15
votes
6 answers

What is the best way to retrieve distinct / unique values using SPQuery?

I have a list that looks like: Movie Year ----- ---- Fight Club 1999 The Matrix 1999 Pulp Fiction 1994 Using CAML and the SPQuery object I need to get a distinct list of items from the Year column which will populate a…
Alex Angas
  • 59,219
  • 41
  • 137
  • 210
11
votes
7 answers

CAML query that includes folders in result set

I'm trying to write a CAML query that executes against a specific SPList, scoped to a specific folder, recursive from that point, and returns all ListItems (which meet a criteria) and Folders. Here's the code for the query which seems like it should…
Rex M
  • 142,167
  • 33
  • 283
  • 313
6
votes
3 answers

How to get all folders in a SPList, then checking permission "Contribute" for current user

I have a sharepoint list like that: List ---------Folder 1 -----------------Item 1 -----------------Item 2 ---------Folder 2 -----------------Item 1 -----------------Item 2 ---------Folder 3 -----------------Item 1 -----------------Item 2 How can…
3
votes
1 answer

Enumerate all folders in a SharePoint list recursively

Is it possible to get a list of all folders in a SharePoint document library, using SPQuery? Something you could get in file system, if you opened Windows command prompt and ran dir /b /A:D /S The problem is, if you create a simple SPQuery and…
naivists
  • 32,681
  • 5
  • 61
  • 85
3
votes
1 answer

Get items from sharepoint list by Title field with ignore care using Caml or SPQuery

I want to get data from SharePoint List using CAML and filtered by Title with ignore case like Car But with ignore…
Ahmed Magdy
  • 5,956
  • 8
  • 43
  • 75
2
votes
0 answers

SharePoint 2010 CAML Query fails when indexed columns used

I have an SPQuery that has been working fine until my list hit 500 items. q.Query = "" + DefectID + ""; This was successfully returning 1 item where DefectID matched my provided value. Once the list hits 500 items, the query returns 0 items, no…
Callum
  • 77
  • 7
2
votes
2 answers

SPQuery : Joining lists and where in the foreign list

Hello Sharepoint developers ! Have you ever tried to do a join between lists and in both of those lists needed to place a where clause? I can do it in the first list, but can't find out how to place the where in the foreign list. I tried several…
KitAndKat
  • 953
  • 3
  • 14
  • 29
2
votes
1 answer

SPQuery and RowLimit

I have around 10000+ rows(Listitems) in a list I want to query. I want to iterate each of the item in a timerJob - but I cant take all of them at a time since : Object Model Override - NO, ListView threshold - 1000 - in the FARM level and i we…
2
votes
1 answer

SharePoint's List.GetItems(view) returns ALL items instead of filtered view items

I'm trying to get a count of items in a list, based on a view. Every method I've tried so far only returns the grand total of the list. I've tried just about every method I've run across while searching, and everything ends up with the same…
SeanW
  • 2,335
  • 6
  • 25
  • 26
1
vote
2 answers

How to filter a Sharepoint:ListView

In VS2010 I have a SharePoint 2010 project with an Application Page. In this simple page I have header information about an order and a SharePoint:ListView for the product detail. So, I just want to filter that ListView by OrderId: SPWeb myWeb =…
1
vote
1 answer

Sharepoint SPQuery on SPView problem

I have created a CAML query to get some particular items on a list, that contains OR: tileA titleB Now the…
matt137
  • 169
  • 1
  • 14
1
vote
2 answers

CAML JOINS using SharePoint

Assume that there are Emp and Dept tables. Emp Table has EmpID FirstName LastName DeptName Email Dept table has DeptID DeptName i have to display all the employee details based on DeptName using CAML query. Can some one share CAML JOINS example…
SP10
  • 91
  • 1
  • 2
  • 11
1
vote
0 answers

Error when connect Android with ontology

I want to connect Android to an owl file using the code below, but this line model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_TRANS_INF) throws an exception. public class OntoQuery { private Model model; public…
eman
  • 33
  • 1
  • 5
1
vote
1 answer

SP 2010 Query CAML - How to sort by multivalue colum lookup field?

I'm trying to sort a list where a column is based on multiple value on a lookup field with the following statement: If I uncheck "Allow multiple values"…
Nicola C.
  • 2,717
  • 3
  • 18
  • 25
1
vote
1 answer

Sharepoint list Dynamic Linq query

I need to query a list in SharePoint where the columns may be added in the future. For instance at the moment I have the following columns Name, Job, interests, address I want to be able to query this string dynamically using a parameter from the…
1
2 3