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.
The FileNotFoundException is thrown by SharePoint when it cannot find the requested site collection in the SharePoint configuration database. My guess is that you have not yet created a site collection on the URL http://mysite:80. I see the following stack trace if I try and instantiate a new SPSite object with the URL of a non-existing site collection:
Specify the proper URL of your site collection or open Central Administration and create a new Site Collection.
We had this same Issue, but I am familiar with the different causes, here is a summary:
It's also possible that the object model doesn't like the URL you're giving it. If you don't provide it with either the exact URL at which you created the site collection or an exact URL listed in your is configured in your Alternate Access Mappings, it will throw an exception that might not necessarily make sense. In your case you might try
http://mysite
orhttp://machinename
.Stacktrace of the exception would be helpful.
I think you possibly can get some idea of what file it is and what is happening by disabling "just my code" in tools -> options -> debugging and looking at the filename argument in the call stack of the exception when the debugger shows it (if you can debug it of course), or maybe the name shows up in the exception message.
Check your web.config and see if there's a config there with a file missing.
Look in you 12 hive for the log. If your log settings are correct, you'll get the file missing.
EDIT: Check also if ALL your DLL are in the GAC. Check if your web.config file contains all the information: namespace,Classname, NameSpace, Version=version_number, Culture-your_culture, PublicKeyToken=your_signed_token
I have recently discovered that this problem with the constructor can be cause by starnge behaviour of the constructor.
I'm taking about MOSS 2007. When you're passing a full site URL to the constructor, what it seems to do is to really consider only the site portion of the URL, choosing the web application which is 'currently seleced' in the web application selector control.
Thus, for example, when you have "http://webapp/sites/site" and have "http://weabapp:22345" currently selected (the last time you selected it in such a selector) when you call
It tries to actually create a site object for "http://webapp:22345/sites/site" and fails.