Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 528179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:57:36+00:00 2026-05-13T08:57:36+00:00

I want to dynamic caml query based on query string.Let me explain it with

  • 0

I want to dynamic caml query based on query string.Let me explain it with example

my query sting can be anything

?cat=ABC&cat=ABD&cat=ABE...
?Cat=ABC
?Cat=ABC&cat=ABL

so no. can be anything now the problem begins

I want to query my sharepoint list based on this query string

if (HttpContext.Current.Request.QueryString["cat"] != null)
        {
            string _cat = HttpContext.Current.Request.QueryString["cat"].ToString();
        }

so this way my string contains all the query

string _cat=ABC,AD,....all.

I want to query my sharepoint list based on these query string and with “AND”

where title=ABC and title=AD ....

if there is only one query string then only
where title=ABC….so I want my query string should be dynamic….
Any idea how to acheive this??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T08:57:37+00:00Added an answer on May 13, 2026 at 8:57 am

    Assuming you are talking about a Multi-select choice field… most likely you will have to create the query each time.

    Your code is going to need to determine how many categories are passed in and then generate the CAML. For example, if only ABC is passed your query would be (notice there are no <And> tags):

    <Where>
      <Eq>
        <FieldRef Name='Category'/>
        <Value Type='Choice'>ABC</Value>
      </Eq>
    </Where>
    

    But if you have three choices passed in via QueryString: ABC, ABD, and ABE you would get (notice the <And> tags surround each group of two):

    <Where>
      <And>
        <And>
          <Eq>
            <FieldRef Name='Category'/>
            <Value Type='Choice'>ABC</Value>
          </Eq>
          <Eq>
            <FieldRef Name='Category'/>
            <Value Type='Choice'>ABD</Value>
          </Eq>
        </And>
        <Eq>
          <FieldRef Name='Category'/>
          <Value Type='Choice'>ABE</Value>
        </Eq>
      </And>
    </Where>
    

    Edit:

    static void Main(string[] args)
    {
        try
        {
            string[] parameters = { "ABC", "DEF", "GHI" };
            string camlQuery = CreateCAMLQuery(parameters);
            Console.WriteLine(camlQuery);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
        Console.WriteLine("Press any key...");
        Console.ReadKey();
    }
    
    private static string CreateCAMLQuery(string[] parameters)
    {
        StringBuilder sb = new StringBuilder();
    
        if (parameters.Length == 0)
        {
            // perhaps set a default query?
            AppendEQ(sb, "all");
        }
    
        // "AND" each parameter to the query
        for (int i = 0; i < parameters.Length; i++)
        {
            AppendEQ(sb, parameters[i]);
    
            if (i > 0)
            {
                sb.Insert(0, "<And>");
                sb.Append("</And>");
            }
        }
    
        sb.Insert(0, "<Where>");
        sb.Append("</Where>");
    
        return sb.ToString();
    }
    
    private static void AppendEQ(StringBuilder sb, string value)
    {
        // put your field's internal name in place of Category
        sb.Append("<Eq>");
        sb.Append("<FieldRef Name='Category'/>");
        sb.AppendFormat("<Value Type='Choice'>{0}</Value>", value);
        sb.Append("</Eq>");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 385k
  • Answers 385k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'd say that it is a combination of readability and… May 14, 2026 at 11:25 pm
  • Editorial Team
    Editorial Team added an answer something like... <script type="text/javascript" src="<%= Url.Content ("~/Scripts/jquery.js") %>"> </script> will… May 14, 2026 at 11:25 pm
  • Editorial Team
    Editorial Team added an answer For additional information, in xhtml strict you have to place… May 14, 2026 at 11:25 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.