Can't connect to existing site

I have tried following some of the examples I have found online, with regards to connecting to a sharepoint site (e.g. SPSite siteCollection = new SPSite("http://<site>"); )
If I try to build and run just this line, I get the following exception: "The type initializer for 'Microsoft.Sharepoint.CoreResource' threw an exception".

Currently, I have "using"s for Microsoft.Sharepoint, Microsoft.Sharepoint.Publishing.WebServices, and Microsoft.Office.Server, anyone have any ideas?

Thanks.

[537 byte] By [eagle123msu] at [2008-1-1]
# 1
Are you aware that this code will only run on the sharepoint server that hosts the http://<site> address? it will not work on any other server or desktop machine.
IshaiSagi at 2007-9-12 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...
# 2

Hi,

I am run the same code on microsoft sharepoint server,

i.e SPSite site = new SPSite("url");

but i got FileNotFoundException

i.e

The Web application at "url" 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.

i am logging as site administrator, then also i got same exception,

can any body help me.

AshvinVaidya at 2007-9-12 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...
# 3
So what are you suggesting? What is the correct way to do this? And where did you read about this problem? Is it documented anywhere?

Thanks, /V

vincentthecat at 2007-9-12 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...
# 4

eagle123msu wrote:
I have tried following some of the examples I have found online, with regards to connecting to a sharepoint site (e.g. SPSite siteCollection = new SPSite("http://"); )
If I try to build and run just this line, I get the following exception: "The type initializer for 'Microsoft.Sharepoint.CoreResource' threw an exception".

Currently, I have "using"s for Microsoft.Sharepoint, Microsoft.Sharepoint.Publishing.WebServices, and Microsoft.Office.Server, anyone have any ideas?

Thanks.

I don't know which type of sharepoint you are using . By the namespaces you indicated above ,I guess it's a MOSS? If so , it definitely works by using

Code Snippet

SPSite newSite = new SPSite(@"MOSSServer_URL/sites_url"); //if this newSite returns null, you probably got the wrong address or like Ishai said, you don't have a valid MOSS on it

SPWeb newWeb = newSite.OpenWeb();

if you are using SPS 2003, the method in the SDK will work for obtaining the all sites and subsites under the same virtual server(which doesn't for MOSS for me...)

Code Snippet

using Microsoft.SharePoint.Administration;

SPGlobalAdmin myGlbAdm = new SPGlobalAdmin();
foreach(SPVirtualServer myVServer in myGlbAdm.VirtualServers)
{
if(myVServer.State != SPVirtualServerState.Ready || myVServer.Sites.Count <= 1)
continue;

SPSiteCollection allSites= myVServer.Sites;
foreach(SPSite thisSite in allSites)
{

SPWeb thisWeb = thisSite.OpenWeb();//this will get the top level web in this collection open

}

}

Hope this helps

JianZhang at 2007-9-12 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...
# 5

A filenotfound error means that the user you are using doesnt have enough permissions on the SQL database. See my blog article:

Content Query limitations, and Object module access rights requirements

IshaiSagi at 2007-9-12 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...
# 6

how to solve it when i would like to upload the file which is locate at remote client site.

it is fine in server site.

Thanks

leekalun at 2007-9-12 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...
# 7
Hello,
"Are you aware that this code will only run on the sharepoint server that hosts the http://<site> address? it will not work on any other server or desktop machine."

ok....i am facing the same problem.... here... for 2 days now... is there any workarround this? any other solution? what can i use instead of spsite? i am trying to make an application that doesn`t run on the sharepoint server...
pleease help....

BBluEE at 2007-9-12 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...
# 8

use web services to do what you want if your code is remote

IshaiSagi at 2007-9-12 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...
# 9
I am also having the same problem as the people above. MOSS is running on a server, and I want to develop for it using the Visual Studio installed on my desktop. I tried running the same code from an asp.net web service project, but I get the same result. Is there anyway to remotely connect to the sharepoint in code?
MattHenry at 2007-9-12 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...
# 10

No.

The only way to "remotely connect" is by using the SharePoint Web Services.


Any and all object model code must run on the same physical and logical machine as SharePoint itself

MKeeper at 2007-9-12 > top of Msdn Tech,SharePoint Products and Technologies,SharePoint - Development and Programming...

SharePoint Products and Technologies

Site Classified