How to open sharepoint site in InfoPath by coding ?

I have written this code,

SPSite site = new SPSite("http:/MyServer/sites/MySite/");

SPWeb web = site.OpenWeb();

but it throws this error. "The Web application at http:/MyServer/sites/MySite/ could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application."

So How should I open my site to perform my operation ?

  • Daft question perhaps, but I'm not sure how InfoPath treats code... is it building to x64 or Any, rather than x86? Building to the wrong architecture will cause the object model to throw a FileNotFound exception on the SPSite constructor.
    – James Love
    Jan 23, 2013 at 21:16

2 Answers 2


Use // after http: for example "http://MyServer/Sites/MySite" and try to run the code again.

  • I have used this but its not working. (Actually this was written for this post only, because it was throwing an error while submitting the question).
    – Shahid
    Jan 5, 2013 at 3:44

This is a guessing game since no details were provided.

This code fail in sandbox on Sharepoint server.

If the form was not sandboxed on Sharepoint server then there are dozens of variants depending on:

  • where to it was published - to client machine or to Sharepoint server,
  • whether it was web-enabled and whether web-enabled forms are permitted to run on server, etc.
  • what are authentication methods used and under which user with which privileges this form is run
  • what is the trust level of the form
  • etc.

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.