Thursday 6 March 2014

System.IO.FileNotFoundException: The Web application at URL could not be found

System.IO.FileNotFoundException: The Web application at URL could not be found
using (SPSite site = new SPSite(sourceWebUrl))
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.
Resolution
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.
Platform target should be 64bit
Right-click on the solution/project
Click Properties
Switch to the “Build” tab
Make sure to change the dropdown to x64
Now re build and deploy