1

I am developing an app for my site. I have an external list that displays all the data i need fine. I need to somehow get that data in Visual Studio 2013 so i can loop through the data and create a dynamic dropdown (<select>). Any documentation or help is greatly appreciated.

  • I just submitted an answer, but realized afterwards, that you used the term app. Does this mean you are attempting to build an solution using the App model and need the information to do it from the client as opposed to server side code? – David Drever Jan 11 '16 at 21:06
  • You'll have to forgive my ignorance but i am not all familiar with doing this. I got confused because the external list is considered an App. I think by App i mean Web Part. I created a new SharePoint project in VS2013 so i could create my own web part that would include a dropdown list of the external list data. – IE5Master Jan 12 '16 at 14:25
  • So in SharePoint 2013, everything is called an App. It's especially confusing to users new to the environment. There is no way why you can't do it the way you are. Anyways, while they call the external list an app, it's still just a list. You can create your web part as you want (there is a lot of information out there on the steps). When it comes down to getting the data from an external list, you can implement the code I used below to do so. I would be happy to blog something specifically for you to illustrate, but my week is pretty packed. If I am able to do so, will reply here. – David Drever Jan 12 '16 at 14:51
  • If you could that would be great! I would like to learn/read more about this topic. Thank you @DavidDrever – IE5Master Jan 12 '16 at 15:55
1

So remember, for all intents and purposes, an External list, for all that it gets its data from an external source is still a SharePoint list.

If I am url is spSnippet.com, external list is called ExternalList and the field I need is FieldForDropdown (real imaginative I know) then my code is simply:

using(SPSite spSite = new SPSite("http://spSnippet.com"))
{
  using(SPWeb spWeb = spSite.RootWeb)
  {
    SPList spExternalList = spWeb.GetList("/Lists/ExternalList");
    List<string> dropdownList = new List<string>();

    foreach(SPListItem spItem in spExternalList.Items)
    {
        dropdownList.Add(spItem["FieldForDropdown"].ToString());
    }
  }
}

You can now use the list dropdownList to build your drop down as needed.

Please note: this is just code I threw together and hasn't been tested. You will likely need to modify for your needs.

  • Thanks for the help, I was able to use your suggestion and some other code i found to get the external list data in C#. Please, blog about this topic as i am still very interested in it. Thank you. – IE5Master Jan 14 '16 at 19:08
  • 1
    Glad I could help. I hope to. It's on my ever growing list of items to throw up on my blog. – David Drever Jan 14 '16 at 19:44

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.