1

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?

2 Answers 2

1

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.

0

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.

1
  • 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. Aug 3, 2012 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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