.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

CAML Query - Wildcards or build dynamically?

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :C#

From what I have found so far, there is no Wildcard in CAML queries against a SharePoint List.  If there is, please let me know what that is.  My problem is that I have seven search criteria that may or may not have data in them.  If a criteria contain spaces or "ALL", I don't want it to be part of the search.  I need those fields to either be wildcarded or be excluded from the query altogether.

If there is no wildcard, does someone have an example of some looping code that will be the query dynamically based on whether a criteria has spaces (or "All) or has data? 

I also am using a DateTimeControl with DateOnly.  I anticipate that will be throwing a wrench into by search results against the SharePoint list.  In the list, it is a datatype of DateTime but "Date Only" is specified.  Any advice about what to watch out for on date fields would be appreciated as well.

View Complete Post

More Related Resource Links

How to join two sharepoint list in c# by CAML query?

Hii All,
   I am using wss 3.0 and i have one site and site has 4 to 5 lists. lists are interconnected with lookup column and same column. I need to display some column fron one list and some from another.. i need to join that lists by where condition like project =project..

So how can i join??

Thank You

Any way to execute a workflow when a caml query returns zero items?

Lets say I have a list with a status column and I want to execute a workflow when all items in the list have a status of complete. I basically want to execute a workflow when the caml query looking for non-complete statuses returns zero rows. Can I do this with SPD or are there any 3rd party tools for this? I'm thinking of writing one if there are not.

Caml query not working

Hi, I'm trying to query a SPListItem from a sharepoint list but it doesn't seem to work:   SPDocumentLibrary myDocuments = (SPDocumentLibrary)site.Lists["Documents"]; SPQuery query = new SPQuery() { Query = " <Where>" + " <Eq>" + " <FieldRef Name='DocumentPath' />" + " <Value Type='Text'>" + source + "</Value>" + " </Eq>" + " </Where>" }; var result = myDocuments.GetItems(query); I get no result, but there's an item with the specified "source" that does exist.

Need help in CAML Query - Sort Operation

hi I have a list column "DisplayOrder" in which i have integer values, i am using this query <Query><OrderBy><FieldRef Name="DisplayOrder" Ascending="True" /></OrderBy></Query> this returns me listcollection 1 10 15 2 it is considering the colums as string, can i convert this column to integer before sorting? i want this result 1 2 10 15

Sorting SPListItemCollection using CAML Query?

Hi, I have a SPListItemCollection from all the list items from a list I retrieve programmatically, is there a way that I can sort by the Title alphabetically?  or sort by date descending? Is there a way to do this?  Can CAML Query do this?  Thanks.

Issue with CAML Query

I am having a RadGrid in Sharepoint Webpart with each row having a checkbox and multiple Columns where one of the Columns is ColumnID. When a multiple checkboxes are selected, their respective ColumnID Value is used to Query and generate report. I am using CAML Query to pass in the ColumnID of each checkbox selected and generate report based on the ColumnID Value. But I am having issue with the Query I have written. I have tried two ways: One of the ways was to Hardcode just two ColumnID Values as I was not sure how to read array of multiple columnID values. But I was wondering where I was going wrong since it was throwing following error: "Multiple with same name ColumnID were used" Telerik.Reporting.ReportParameter param1 = new Telerik.Reporting.ReportParameter(); param1.Name = "ColumnID"; param1.Type = Telerik.Reporting.ReportParameterType.Integer; param1.AllowBlank = false; param1.AllowNull = true; param1.Text = "ColumnID"; param1.Visible = true; param1.Value = "200"; this.ReportParameters.Add(param1); Telerik.Reporting.ReportParameter param2 = new Telerik.Reporting.ReportParameter(); param2.Name = "ColumnID"; param2.Type = Telerik.Reporting.ReportParameterType.Integer; param2.AllowBlank = false; param2.AllowNull = true; param2.Text = &qu

Trying to build query using DISTINCT or GROUP BY...beginner here

Hi all, I have a table with the following format: instanceID    timeStamp  stepID 28B2D4FB-67F6-40CA-84A2-839BF3CC4B91 2010-09-07 20:36:32.807 1 28B2D4FB-67F6-40CA-84A2-839BF3CC4B91 2010-09-07 20:36:33.807 2 28B2D4FB-67F6-40CA-84A2-839BF3CC4B91 2010-09-07 20:36:34.807 3 ... EADD3AAA-5E93-4311-A844-9A7BE53A9606 2010-09-09 22:18:25.757 1 EADD3AAA-5E93-4311-A844-9A7BE53A9606 2010-09-09 22:18:26.773 2 so I need to build a query which will return 1 instanceID and all its stepIDs in one row. So the results would have to be something like this: instanceID    timeStamp  StepIDs 28B2D4FB-67F6-40CA-84A2-839BF3CC4B91 2010-09-07 20:36:32.807 1,2,3 EADD3AAA-5E93-4311-A844-9A7BE53A9606 2010-09-09 22:18:25.757 1,2 and if possible I would like to specify something like...bring me the data where 'timeStamp' > 2010-09-07 20:35 ps: I tried using DISCTINCT and GROUP BY but could not reach the desired results. Thank you!JCD

Dynamically Setting the property value FilterValue1 of the Content Query WebPart? Inline? codeblock?

I want to dynamically set the FilterValue1 property of a Content by Query to the querystring ID. I tried to do it with an inline embed FilterValue1="<%= Reponse.Write .. but no luck Without having to code my own webpart, any way to change the value with a small C# code block? How about with javascript? Thank you!    

Parse XML To build Dynamic Query

Hi All, I am trying to figure out the best way to handle a scenario where I will be passed XML that will contain criteria for a search. If the user has selected specific filters then those will be sent in the XML and if there is a section that they left unfiltered then it will not be present in the XML (Which would mean everything for that filter should be returned). My question is around the best process to shred the XML and build a dynamic query out of what i am getting out of the XML object. Is there a better way to handle this scenario? Here is my current approach: Shred the XML and put the filtered data into Global Temp Tables so that I can use them to build my dynamic query. Use those temp tables to create "Where Exists" Criteria within the query to filter down the results based on what was passed to me in XML. If one of the search criteria sections wasn't filtered the temp table would have zero rows and I wouldn't add that to the where clause with an exists statement. I used FOR XML PATH('') in the queries to roll up the data into comma separated values. Build the test schema / objects:   -------------------------------------------------------- --Build Test Schema to demonstrate XML Parsing -------------------------------------------------------- SET NOCOUNT ON; IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[test].[Products]

caml query builder for wss 3 site

hi, is there a caml query builder that can be use for WSS 3.0 sites?

CAML query on external list is not working

Hi, I have an external list, display data from SQLServer 2008. Table on SQL have an UniqueIdentifire (GUID) type column as a Primary key. It also has one identifier column, Its value is increased by 1, as the item is created. In share point server side code, I want to fetch single record against the primary key GUID value. I write down the CAML query on GUID column and run without any error. But all the external list data is returned instead of Single list item. I also try to filter on Auto Incremented column, but same problem is occurred.

CAML query to access List data across multiple site collection.

Hi   Is there any way to get the Task List data across multiple site collection using CAML query. Currently, I have the code which will retrieve the data from a single site collection. Below is the code.                           /***************************************************I am using Moss2007.Thanks!Ravi             SPSiteDataQuery q = new SPSiteDataQuery();             q.ViewFields = "<FieldRef Name=\"Title\" />" "<FieldRef Name=\"Status\" Nullable=\"TRUE\"/>";             q.Lists = "<Lists ServerTemplate=\"107\"/>";             q.Webs = "<Webs Scope=\"SiteCollection\"/>";             q.Query = "<Where>" +                                "<Eq>" +                                     "<FieldRef Name=\"Status\" />" + "<Value Type=\"Choice\">Not  Started</Value>" +                                     "</Eq>" +                         "</Where>";             DataTable dt=null;             using (SPSite s = new SPSite("http://banglabguest1:31000/"))             {                 SPWeb w = s.OpenWeb();                 dt = w.GetSiteData(q);                 w = null;             }                              *************************

Dynamically fill query parameters in a table adapter ?

SO I have created an object data source on a page from a table adapter using the various Wizards in Visual Studio.Its meant to query a diary Database by a DateTime parameter called diaryDate. I want to query from a date Now to the next 14 days ahead.I want to display the entries in a Grid View when the page loads.So I'm a bit stuck now as to how to set the two query parameters date1 and date2. I want to set date1 = now() and date2 = now() + 14 days.How do I set those parameters when the page loads ?Should I have used the adapter Wizard approach of do I have to write all the code in the code behind page ??This is my datasource code'<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" SelectMethod="GET_nextTwoWeeks" TypeName="query_getNextTwoWeeksTableAdapters.diaryDatesTableAdapter"> <SelectParameters> <asp:FormParameter DefaultValue="" FormField="date1" Name="date1" Type="DateTime" /> <asp:FormParameter DefaultValue="" FormField="date2" Name="date2" Type="DateTime" /> </SelectParameters> <InsertParameters>

Adding a table or view multiple times when building a query with BI Report Designer and Report Build

How can I add a table/view multiple times to a single query by using BI Report Designer or Report Builder 3.0? In Report Designer I managed (workaround) to add one table multiple times by creating multiple Named Queries and having the same SELECT. Still I don't know how to add one table multiple times in Report Builder 3.0.

CAML Query - DateTime

I wish to take data from the list, satisfying to the certain time range (BeginDate.....DateTime.....EndDate). How it can be made?

CAML query to pick docs where modified is older than today.


Hi I am looking for a CAML query which will return all documents throughout the site collection
for docs which have a Modified that have past today.
I cant seem to do this.

I have a query so far as this and it comes up with an error 'The property Query contains invalid value'

SPSiteDataQuery q = new SPSiteDataQuery();
q.ViewFields = "<FieldRef Name=\"Modified\"/>";
q.Lists = "<Lists ServerTemplate=\"101\"/>";
q.Webs = "<Webs Scope=\"SiteCollection\"/>";
q.Query = "<where><Geq><FieldRef Name='Modified' /><Value Type='DateTime'><Today OffsetDays='-1' /></Value></Geq></where>";

How do you do this ??

Best way to build a query /sproc to support filtering


Hi All,


I have a scenario where I will be getting search results from a front end UI.  If nothing is passed I should return all results, but if the users have selected one to many choices I will need to filter based on those choices.  My delima is how to handle this approach.  The data will be coming in the form of XML and I will need to shred it to get the criteria.

I was thinking I could use "WHERE EXISTS" Clauses and if there are any results passed to me I could fill a table variable with everything and join to it.....if they did make selections then I could fill the table with just those choices. 

I really just don't like the idea of having to fill the table with everythign when nothing is selected. 

Just wondering what others have done to handle this type of scenario?

Thanks !


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend