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

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

2 Answers 2

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

 
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.