SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have got a problem to read data from External List. I getting this error while I reading a External Lists: Exception Details: System.Xml.XmlException: Name cannot begin with the '-' character, hexadecimal value 0x2D. Line 1, position 312.

A External List look like this: enter image description here

And no one coolumn from CRM View have got "-"

Error on Visual Studio is: enter image description here

And After this Error shown at site shown this log: enter image description here


Here is my code for this loop:

   string FullQueryUrlap = "<Where><And><Geq><FieldRef Name='{0}' /><Value IncludeTimeValue='TRUE' Type='DateTime'>{1}</Value></Geq><And><Leq><FieldRef Name='{2}' /><Value IncludeTimeValue='TRUE' Type='DateTime'>{3}</Value></Leq><Eq><FieldRef Name='LoginName' /><Value Type='Text'>{4}</Value></Eq></And></And></Where>";
        string dateISO1 = SPUtility.CreateISO8601DateTimeFromSystemDateTime(e.Day.Date.ToUniversalTime().AddHours(1.0));
        string dateISO1zm = String.Format("{0:dd-mm-yyyy}", dateISO1);
        string dateISO2 = SPUtility.CreateISO8601DateTimeFromSystemDateTime(e.Day.Date.ToUniversalTime().AddHours(2.0));
        string dateISO2zm = String.Format("{0:dd-mm-yyyy}", dateISO2);

      //  int spacja = DropDownList1.SelectedItem.Text.IndexOf(" ");

        var queryPoszczegolnyUrlop = new SPQuery();
        queryPoszczegolnyUrlop.Query = String.Format(FullQueryUrlap, "data_kon", dateISO1zm, "data_poc", dateISO2zm, DropDownList1.SelectedItem.Text);
        queryPoszczegolnyUrlop.ViewFields = "<FieldRef Name='nazwa' /><FieldRef Name='data_poc' /><FieldRef Name='data_kon' />";
        queryPoszczegolnyUrlop.ViewFieldsOnly = true;

        // Wy┼Ťwietlanie poszczeg├│lnego pracownika wybranego z DropDownList1
        //      Label2.Text = DropDownList1.SelectedItem.Text.ToUpper().Substring(0, spacja) + DropDownList1.SelectedItem.Text.ToUpper().Substring(0, spacja).Length + " | " + DropDownList1.SelectedItem.Text.ToUpper().Substring(spacja+1) + DropDownList1.SelectedItem.Text.ToUpper().Substring(spacja+1).Length;

        SPListItemCollection listaDniUrlopow = witryna1.Lists["Urlopy_prac"].GetItems(queryPoszczegolnyUrlop);

        DateTime dataPoc = new DateTime();
        DateTime dataKon = new DateTime();

        for (int interator = 0; interator < listaDniUrlopow.Count; interator++)
            SPListItem item = listaDniUrlopow[interator];
            dataPoc = Convert.ToDateTime(item["data_poc"]);
            dataKon = Convert.ToDateTime(item["data_kon"]);

            if (e.Day.Date.Date.DayOfWeek == DayOfWeek.Saturday || e.Day.Date.Date.DayOfWeek == DayOfWeek.Sunday)
                e.Cell.Style.Add("background-color", "#FF9900");
                e.Cell.CssClass = "dni_swiateczne";
                e.Cell.Style.Add("background-color", "#EB5200");
                e.Cell.CssClass = "dni_swiateczne";
                e.Cell.Controls.Add(new LiteralControl(("<p style='color:#692E00; font-size:9px;'>" + item["nazwa"].ToString() + "</p>" + "<p style='color:#000000; font-size:8px;'>od: " + dataPoc.ToString().Substring(0, 10) + "</p>" + "<p style='color:#000000; font-size:8px;'>do: " + dataKon.ToString().Substring(0, 10) + "</p>")));
                //  e.Cell.ForeColor = System.Drawing.ColorTranslator.FromHtml("#FFCC66");


enter code here
share|improve this question
can you put your code up? what is in the for loop? what is being hidden by the error message? – TZHX Dec 17 '12 at 14:40
Hello TZHX :) Upgraded my Question – Grzegorz Z Dec 17 '12 at 14:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.