title: Get SharePoint List columns
body: <p>I am programing a custom field type where the user can type a site URL, select a site and select a column of the selected list. </p>
  
  <p><strong>How do I get the columns of the list?</strong></p>
  
  <p>What I have tried now seams to work but I am receiving all too much data. Here is how i get the columns:</p>
  
  <pre><code>private void getColumnsOfSelectedList()
  {
      DdlLookupFieldDataList.Items.Clear();
  
      if (!string.IsNullOrEmpty(LabelLookupFieldTargetURLText.Text))
      {
          //Get the lists of the site from the Site URL
          site = new SPSite(LabelLookupFieldTargetURLText.Text);
          SPWeb web = site.OpenWeb();
  
          foreach (SPList list in web.Lists)
          {
              if (list.Title == DdlLookupFieldTargetList.SelectedItem.Text)
                  foreach (var item in list.Fields)
                      DdlLookupFieldDataList.Items.Add(item.ToString());
          }
      }
  }
  </code></pre>
  
  <p>BR</p>