Madhawa Learns To Blog : C#, Java

.net, c#, java,sql, OOAD and more mad memory dumps...

  Home  |   Contact  |   Syndication    |   Login
  47 Posts | 0 Stories | 57 Comments | 15 Trackbacks

News

Archives

Post Categories

Blog Roll

Hang Outs

My old blog

 public static List<string> GetChoiceFieldValues(string listName,string fieldName, string siteCollection, string webSite)
        {
            List<string> fieldList;

            SPSite spSite = null;
            SPWeb spWeb = null;

            try
            {
                if (siteCollection != null)
                    spSite = new SPSite(siteCollection);
                else
                    spSite = SPContext.Current.Site;

                if (webSite != null)
                    spWeb = spSite.OpenWeb(webSite);
                else
                    spWeb = spSite.OpenWeb();

                SPList spList = spWeb.Lists[listName];

                SPFieldChoice field = (SPFieldChoice)spList.Fields[fieldName];

                fieldList = new List<string>();

                foreach (string str in field.Choices)
                {
                    fieldList.Add(str);
                }
            }
            catch (Exception ex)
            {
                LogException(ex);
                throw;
            }
            finally
            {
                if(spWeb != null)
                    spWeb.Close();

                if(spSite != null)
                    spSite.Close();
            }

            return fieldList;
        }

 

posted on Saturday, August 1, 2009 4:01 AM

Feedback

# re: Get value collection of a SharePoint Choice Field 8/17/2009 6:39 PM Merill Fernando
Imagine that. Your post saved me from spending a lot of time!

Cheers,
Merill

- It's a small world.

# re: Get value collection of a SharePoint Choice Field 8/17/2009 7:59 PM Madhawa
I just pasted the method from my class, as it was. I know this will come in handy in future, at least for me. I'm glad it saved your time. :)

Cheers

# re: Get value collection of a SharePoint Choice Field 9/10/2009 10:39 PM Danushka Silva
Hey it's relly helpfull. Thanks.

# re: Get value collection of a SharePoint Choice Field 3/31/2010 8:22 AM Yahav
Thanks man, this was really useful for me. :-)

# re: Get value collection of a SharePoint Choice Field 7/18/2010 2:30 AM ZooZ
Thanks a lot man. This saved me alot of time :-)

# re: Get value collection of a SharePoint Choice Field 2/3/2011 12:13 PM sharda
very usefull ,thanks

# re: Get value collection of a SharePoint Choice Field 8/3/2011 12:51 PM sema
thanks for the help. saved a lot of time.

# re: Get value collection of a SharePoint Choice Field 7/19/2012 7:41 AM Sameer Shah
Really nice. Thanks.

# re: Get value collection of a SharePoint Choice Field 12/20/2012 11:29 AM Andy
Nice one, saves heaps of time!

Post A Comment
Title:
Name:
Email:
Comment:
Verification: