0

I am new to SharePoint Services and I hit a wall with one of my tasks. I need to retrieve data from a Site Column. How do I get about that? So far I only see APIs that can retrieve lists and not site columns.

Please let me know if any of you know to do this.

Thanks !!

Benjamin Wong
  • 599
  • 1
  • 8
  • 21
  • What do you exactly trying to retrieve? – Flo Dec 03 '09 at 16:37
  • please write down more precise exactly what you are trying to achieve. Do you want to retrieve info (i.e. the schema) about the site column, or do you want to retrieve a number of items and include the column in the result set. (i.e. like the sql equivalent 'select column name from list') – Colin Dec 03 '09 at 17:27

1 Answers1

2
using(SPSite site = new SPSite("http://portal"))
{
    using (SPWeb web = site.RootWeb)
    {
        foreach (SPField field in web.Fields)
        {
            Console.WriteLine(field.Title);
        }
    }
}

These will give you all the columns for a web (in this case, the RootWeb). If your site column is related to a list, you need to get directly from the SPListItem property (ex.: item["CustomAssociatedColumn"])

Francisco Aquino
  • 9,097
  • 1
  • 31
  • 37
  • Thanks there, I was actually trying to retrieve the Statuses from the Tasks list from a site. I would really appreciate it if you can show how its done. Anyway again, thanks again for answering my question. – Benjamin Wong Dec 04 '09 at 00:37
  • Resolved the thing, you have been a great help F.Aquino. Hope to be able to return the favor one day :) – Benjamin Wong Dec 04 '09 at 03:44