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.
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.
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
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?
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