Geeks With Blogs
Madhawa Learns To Blog : C#, Java .net, c#, java,sql, OOAD and more mad memory dumps...

 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 .net , .net 3.0 , MOSS , MOSS Object Model | Back to top


Comments on this post: Get value collection of a SharePoint Choice Field

# re: Get value collection of a SharePoint Choice Field
Requesting Gravatar...
Imagine that. Your post saved me from spending a lot of time!

Cheers,
Merill

- It's a small world.
Left by Merill Fernando on Aug 17, 2009 6:39 PM

# re: Get value collection of a SharePoint Choice Field
Requesting Gravatar...
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
Left by Madhawa on Aug 17, 2009 7:59 PM

# re: Get value collection of a SharePoint Choice Field
Requesting Gravatar...
Hey it's relly helpfull. Thanks.
Left by Danushka Silva on Sep 10, 2009 10:39 PM

# re: Get value collection of a SharePoint Choice Field
Requesting Gravatar...
Thanks man, this was really useful for me. :-)
Left by Yahav on Mar 31, 2010 8:22 AM

# re: Get value collection of a SharePoint Choice Field
Requesting Gravatar...
Thanks a lot man. This saved me alot of time :-)
Left by ZooZ on Jul 18, 2010 2:30 AM

# re: Get value collection of a SharePoint Choice Field
Requesting Gravatar...
very usefull ,thanks
Left by sharda on Feb 03, 2011 12:13 PM

# re: Get value collection of a SharePoint Choice Field
Requesting Gravatar...
thanks for the help. saved a lot of time.
Left by sema on Aug 03, 2011 12:51 PM

# re: Get value collection of a SharePoint Choice Field
Requesting Gravatar...
Really nice. Thanks.
Left by Sameer Shah on Jul 19, 2012 7:41 AM

# re: Get value collection of a SharePoint Choice Field
Requesting Gravatar...
Nice one, saves heaps of time!
Left by Andy on Dec 20, 2012 11:29 AM

Your comment:
 (will show your gravatar)


Copyright © Madhawa Karunaratne | Powered by: GeeksWithBlogs.net | Join free