Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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 ?

share|improve this question
add comment

2 Answers

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);
share|improve this answer
add comment

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.

share|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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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