Jakew
Consulting, hacking, and motorcycles

How to get context for a SharePoint web part

Monday, 28 September 2009 08:25 by jakew

This one turned out to be really easy:

The WSS (Windows SharePoint Services) object model has a static object called SPContext that you can use to get the context that your control is working in.  For instance if you want to grab a list from the site, you would do the following:

            SPWeb thisWebSite = SPContext.Current.Web;
            SPList spContactList = thisWebSite.Lists["Contacts"];
            foreach(SPListItem contact in spConactList)
            {
                //do some work
            }

Pretty cool stuff. The more I get in to SharePoint’s API the more I’m liking it.

Categories:   Tech
Actions:   E-mail | del.icio.us | Permalink | Comments (0) | Comment RSSRSS comment feed