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 gotten two lists (like a view) from Microsoft Dynamics CRM. How can I get a elements from these two lists to the C# Sharepoint code in .cs file. The Administrator of CRM told me that this lists are made by Business Data Connectivity. How can I call them from the code? How to put CAML Query to it?


Here is my example of code:

            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><And><Eq><FieldRef Name='Nazwisko' /><Value Type='Note'>{4}</Value></Eq><Eq><FieldRef Name='Imie' /><Value Type='Note'>{5}</Value></Eq></And></And></And></Where>";
        string dateISO1 = SPUtility.CreateISO8601DateTimeFromSystemDateTime(e.Day.Date.ToUniversalTime().AddHours(1.0));
        string dateISO2 = SPUtility.CreateISO8601DateTimeFromSystemDateTime(e.Day.Date.ToUniversalTime().AddHours(2.0));

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

        var queryPoszczegolnyUrlop = new SPQuery();
        queryPoszczegolnyUrlop.Query = String.Format(FullQueryUrlap, "DataKon", dateISO1, "DataPoc", dateISO2, DropDownList1.SelectedItem.Text.ToUpper().Substring(0, spacja), DropDownList1.SelectedItem.Text.ToUpper().Substring(spacja+1));
        queryPoszczegolnyUrlop.ViewFields = "<FieldRef Name='Title' /><FieldRef Name='DataPoc' /><FieldRef Name='DataKon' />";
        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["ListaUrlopow2012"].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["DataPoc"]);
            dataKon = Convert.ToDateTime(item["DataKon"]);

Hov could I get a Internal name of the Esential list in BDC.

share|improve this question
Are you trying to get CRM data into SharePoint or SharePoint data into CRM? – John Chapman Dec 7 '12 at 4:00
CRM data into Sharepoint. The Administrators of CRM shared me databy Business Data Conectivity. How could I read them? – Grzegorz Z Dec 7 '12 at 8:42
What error does the above code give? (other than the syntax for the unclosed for loop) – TZHX Dec 7 '12 at 9:53
The Title field isn't find. But I warried that i can't find in BDC view a Esential List Internal Name – Grzegorz Z Dec 7 '12 at 10:01
If your content type doesn't have a Title field, don't include it in the query. I have difficulty understanding the rest of what you said. – TZHX Dec 7 '12 at 10:28
up vote 1 down vote accepted

IF they are exposed in SharePoint as an External list then you can just read them like a regular list.

share|improve this answer
Please vrite it's as a comment. I have got only a View of list. How could I call them. I updated my question. – Grzegorz Z Dec 7 '12 at 8:51
I found out the Solution :) My Admin don't change Internal Names, He Change only a Display Name, not Internal Name – Grzegorz Z Dec 10 '12 at 9:13

Check my blog for read data from sharepoint list programmatically:

share|improve this answer
While this may theoretically answer the question, we prefer inclusion of the essential parts of the answer here, and to provide the link for reference. See answer for general guidelines. – SPDoctor Mar 6 '13 at 8:35

Your Answer


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

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