0

I have written a wcf service to read the title and id column from a list and returning as arraylist. Please find the below code. The webservice is returing the values correctly.Now when i create an external content type and create external list and use this list as lookup in another list. When i select an item from the lookup it is showig data in the binary format. Attached is the screen shot for the same

 public Vendor[] GetVendors(string fieldTitle)
        {
            string siteName = "http://myappserver.com/myname/";
            string webName = "Susite2";
            string listName = "Vendors List";
            List<Vendor> listVendor = new List<Vendor>();

            using (SPSite site = new SPSite(siteName))
            {
                using (SPWeb web = site.AllWebs[webName])
                //using (SPWeb web = site.OpenWeb())
                {
                    SPList list = web.Lists.TryGetList(listName);
                    if (list != null)
                    {
                        SPQuery query = new SPQuery();
                        query.ViewFields = "<FieldRef Name='Title' />" + "<FieldRef Name='ID'/>";
                        query.ViewFieldsOnly = true;
                        SPListItemCollection items = list.GetItems();
                        if (items.Count > 0)
                        {

                            foreach (SPListItem item in items)
                            {
                                string title = Convert.ToString(item[fieldTitle]);

                                Vendor vendor = new Vendor();
                                vendor.Name = title;
                                vendor.VendorId =item.ID;
                                listVendor.Add(vendor);
                              }
                        }
                    }
                }
            }

            return listVendor.ToArray();

        }

enter image description here

0

Below Code worked for me

public Vendor[] GetVendors(string strFilter)
        {
            string siteName = "http://myappserver.com/myname/";
            string webName = "Susite2";
            string listName = "Vendors List";
            string fieldTitle = "Title";
            List<Vendor> listVendor = new List<Vendor>();

            using (SPSite site = new SPSite(siteName))
            {
                using (SPWeb web = site.AllWebs[webName])
                //using (SPWeb web = site.OpenWeb())
                {
                   SPList list = web.Lists.TryGetList(listName);
                    if (list != null)
                    {
                        SPQuery query = new SPQuery();
                        query.ViewFields = "<FieldRef Name='Title' />" + "<FieldRef Name='ID'/>";
                        query.ViewFieldsOnly = true;
                        if (!string.IsNullOrEmpty(strFilter))
                            query.Query = "<Where><Eq><FieldRef Name='Title'/><Value Type='Text'>" + strFilter + "</Value></Eq></Where>";
                        SPListItemCollection items = list.GetItems(query);
                        if (items.Count > 0)
                        {
                            foreach (SPListItem item in items)
                            {
                                string title = Convert.ToString(item[fieldTitle]);
                                Vendor vendor = new Vendor();
                                vendor.Name = title;
                                vendor.VendorId = item.ID;
                                listVendor.Add(vendor);

                            }
                        }
                    }
                }
            }
                 return listVendor.OrderBy(a => a.Name).Select(a => a).ToArray();
    }

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.