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

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 ?

share|improve this question
    
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 '13 at 21:16
add comment

2 Answers 2

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

share|improve this answer
    
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 '13 at 3:44
add comment

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.
share|improve this answer
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.