I try to instantiate an instance of SPSite
on the farm server in a custom process (MyApp.exe) and I give it as parameter the whole URI (http://mysite:80/). I also made sure that the account running MyApp.exe
is Site Collection Administrator
.
However, I can't make an instance of SPSite
whatever I am trying to do. It always throws a FileNotFoundException
.
Anyone got an idea?
StackTrace:
at Microsoft.SharePoint.SPSite..ctor(SPFarm farm, Uri requestUri, Boolean contextSite, SPUserToken userToken)
at Microsoft.SharePoint.SPSite..ctor(String requestUrl) at MyCompanyName.Service.HelperClass.GetItemStateInSharePoint(SharePointItem item) in C:\Workspaces\MyCompanyName\Development\Main\MyCompanyName.SharePoint\Service\HelperClass.cs:line 555
Another side note... I have a Web Application + Site collection that I can access through the browser without any problem.
We faced the same problem some days ago, and the solution was to set the application, that is trying to create de SPSite object, to use the same AppPool that the Sharepoint's web application.
Hope it helps.
I have similar kind of issue.
In my scenario, I was able to create the instance of SPSite from a console application, but when another team mate tried to do so, the application threw the same exception as mentioned above.
Solution: I added the other teammate as administrator on Content Db server box (this may not be possible for everyone), the code works fine and no error
If it is a console application accessing SharePoint 2010 you make sure your project's Build Target is x64 and the .NET Framework is 3.5.
In my case it was definitely a permissions problem with the account I was logged into windows with.
Try this command in SharePoint Management Shell running as Administrator:
Get-SPSite 'http://yoursite/yourcollection'
If you get errors then logon to the SharePoint server as the app pool user or the account used to install SharePoint and try the above command again.
If it works then you know your previous account has a permissions issue. To fix the problem, run this command in the same shell window and supply the account you want to use in VS:
Add-SPShellAdmin -UserName Domain\User
I had the same problem trying to access Sharepoint 2010.
I fixed it by changing the Target Framework to .NET 3.5.- which is the supported version for Sharepoint 2010.
Read this site http://community.bamboosolutions.com/forums/t/8179.aspx if you are running your OS x64 bit and are using MSTest (32bit) it will fail, use nunit works!!!