Are you a .NET Developer or Contractor interested in working with Sitecore or Dynamics CRM?

Apply for our Mentorship Program. If accepted, we will mentor you on Sitecore and provide you with project to help you build your skills and make some money at the same time. If you are interested send your resume with details on why you want to work with Sitecore or Dynamics CRM to: Chris Williams - chris.williams@techguilds.com or Dennis Augustine - dennis.augustine@techguilds.com We look forward to working with you to achieve your goals.

Wednesday, April 29, 2009

System.IO.FileNotFoundException error when opening SPSite outside IIS

PROBLEM:

When developing against the SharePoint object model in an application outside of IIS (service, console, Winforms etc..) you receive the error “FileNotFoundException” when creating an instance of the SPSite object.

ERROR MESSAGE:

System.IO.FileNotFoundException: The Web application at http:// 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.\n
at Microsoft.SharePoint.SPSite..ctor(SPFarm farm, Uri requestUri, Boolean contextSite, SPUserToken userToken)\n at Microsoft.SharePoint.SPSite..ctor(String requestUrl)\n

SOLUTION:

The user running the application needs to have the following permissions and group membership set:

· The user is a server farm administrator.

· The user has Read and Write permissions on the content database.

· The user is a site collection administrator.

· The user has permissions to access the Windows SharePoint Services site or the SharePoint Server 2007 site through which the code iterates.

REFERENCE LINK:

http://social.msdn.microsoft.com/forums/en-US/sharepointdevelopment/thread/5834679b-482b-4924-b881-fa2146840d05/

2 comments:

will said...

Hi, im trying to develop a new application to insert users in membership and in a sharepoint group.

When i try to call the SPSite constructor, the System.IO.FileNotFoundException error when opening SPSite outside IIS error appears.

i change in the iis the users who runs the applicaton and is the same that i install the sharepoint app so i think that i do the things that you post. any idea?

Anonymous said...

One thing to remember is that the hive is your friend.

In order use the SPSite, SPWeb etc api objects from outside sharepoint there is a set of permissions necessary for the running user, not only on the sharepoint front end but also on the sharepoint databases.

The first hoop you will jump through is going into regedit and navigating to HKLM\Software\Microsoft\Shared Tools\Web Server Extensions\12.0\Secure\ConfigDB

Make sure that your user has access to that key.

The next hoop is giving your user access to the config db

The following hoop is giving your user access to the content db.

After that you will need to find all the stored procedures it needs permission to. The best way to find the permissions you need is to look in the Sharepoint log located in the hive under (C:\program files\Common Files\microsoft shared\Web Server Extensions\12\logs)

As an alternative to granting these permissions, you can also use the web service interface that sharepoint provides. Then your user only needs permissions at the sharepoint web level as opposed to database and regedit.

Here is a list of some of the available services:
http://www.crsw.com/mark/sharepoint/Wiki%20Pages/SharePoint%20Web%20Services.aspx

Hope this helps