0

Hello i have got a problem with making a CAML Query by the string which contains sign "&".

I have Got a "L&M" firm and when I choose it on DropDownList it make me error:

enter image description here

How to use this signs ?

Here is my Code:

   string kontraktNazwa = "<Where><Eq><FieldRef Name='{0}' /><Value Type='Text'>{1}</Value></Eq></Where>";
            var kontraktyWylistowanie = new SPQuery();
            kontraktyWylistowanie.Query = String.Format(kontraktNazwa, "Nr_Encji", DropDownList4.SelectedItem.Text.ToString());
            kontraktyWylistowanie.ViewFields = "<FieldRef Name='Nr_Encji' /><FieldRef Name='Nazwa_Encji' /><FieldRef Name='Klient' /><FieldRef Name='StatusQS' /><FieldRef Name='Stan' />";
            kontraktyWylistowanie.ViewFieldsOnly = true;
            SPListItemCollection kontraktySzczegoly = witryna.Lists["Zespolyv2"].GetItems(kontraktyWylistowanie);
            foreach (SPListItem okontraktySzczegoly in kontraktySzczegoly)
            {
                Label5.Text = okontraktySzczegoly["Nazwa_Encji"].ToString();
                Label6.Text = okontraktySzczegoly["Klient"].ToString();
                Label7.Text = okontraktySzczegoly["StatusQS"].ToString();
                Label14.Text = okontraktySzczegoly["Stan"].ToString();

And If it's comming to DropDownList4.SelectedItem.Text.ToString() it's put me error:

Error in Entity Name Line 1 Position 90.

1

Use HttpUtility.HtmlEncode on the value received from the drop down.

Like

var encodedDropDownValue = HttpUtility.HtmlEncode(DropDownList4.SelectedItem.Text.ToString())

this will encode your special characters to a format that you can add to your CAML query

2

You need to replace L&M with L&amp;M

One way to do this is to use HttpUtility.HtmlEncode

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.