SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On occasion I find that SPContext.Current returns null in the code behind of my InfoPath forms. This is occuring while I have the form open in a SharePoint 2010 site collection. I can't figure why this happens and other times it is fine. Typically I am forced to use this.ServerInfo.SharePointSiteCollectionUrl to get the URL for my SPSite or SPWeb object.

What are the advantages/disadvantages of using this.ServerInfo.SharePointSiteCollectionUrl vs using SPContext.Current?

When should this.ServerInfo.SharePointSiteCollectionUrl be used instead of SPContext.Current?

share|improve this question

I would suggest to move "SPContext.Current"-related code to web services and attach them later as a datasource in you target InfoPath form.

That's a huge "shift" in InfoPath form development, but it improves supportability of InfoPath form, keeps your form kinda light and clean as well as helps you to avoid a lot of issues.

share|improve this answer

SPContext is most probably zero since you are running loacally in application mode and not running the InfoPath form via form services on the actual web site, normally u can pick it up when in debug mode. I'll check how to get around this but you will probably need one set of code for app mode and one set for web mode.

share|improve this answer
Are you talking about when I run the form in debug mode from InfoPath? I know its null there, I'm talking about running a published form from inside SharePoint. It seems only the Form_Load method has SPContext populated. – Meyer Denney Aug 3 '12 at 15:37

Your Answer


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.