Madhawa Learns To Blog : C#, Java

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

  Home  |   Contact  |   Syndication    |   Login
  41 Posts | 0 Stories | 34 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 01, 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.

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