To get current SP objects (SPWeb, SPSite, SPList etc), I generally use SPContext.Current. In some situations, SPContext.GetContext is preferred because SPContext.Current have many objects null depending on where the code runs (Webpart page, Edit item form etc).

Are you aware of any guidelines (may be from Microsoft) on the usage SPContext.Current and SPContext.GetContext ?


Another reason for using the SPContext.GetContext is to set the context of a control to one that is different than the context of the current page. For example, you can set the ItemFieldIterator.ItemContext proprty to get information from a list on different SPWeb object.

myItemFieldIterator.ItemContext = SPContext.GetContext(Context, 0, ListId, oSPWeb);
| improve this answer | |

SPContext.GetContext tends to be used if there is no current context (console app? timer job? FeatureUninstalling?), whereby in the case where you do, you would use the obviously named SPContext.Current.

| improve this answer | |
  • 1
    Good point.I think what you said is specific to SPContext.GetContext(SPWeb) version, all other overloaded versions require HttpContext...which is not there in Console,timer etc. – Amit Kumawat Dec 4 '11 at 3:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.