I am trying to write a console application that simply lists the number of lists in the sharepoint root directory.
I tried to do this using the following code, but the SPContext.Current object is null. Any ideas on how to get the web object?
SPWeb web = SPContext.Current.Site.OpenWeb("http://localhost") ;
SPSite spSite = new SPSite("http://myurl"); SPWeb spMySite = spSite.Allwebs["mysite"]; SPWeb spRootsite = spsite.RootWeb;
The console application will only run on the server, as usual. In addition, the URL http: // myurl may be the URL of the page and an SPSite object will be created. For instance. http: //myurl/mysite/pages/default.aspx will receive a valid SPSite object.
Nat:, SharePoint WebApp, - SPWeb SPSite.:
using (SPSite site = new SPSite(weburl)) { using (SPWeb web = site.OpenWeb()) { // bla bla } }
: weburl SPSite, OpenWeb -.
SPSite.OpenWeb(), ...
GUID SPWeb:
site.OpenWeb(webUid);
URL- - . MSDN SPSite.OpenWeb() :
site.OpenWeb(relativeUrl); site.OpenWeb(title);
URL- , SPSite.OpenWeb():
site.OpenWeb(relativeUrl, true);
Source: https://habr.com/ru/post/1699546/More articles:How can I access element attributes from IXMLDOMNode? - c ++SSH freezes on Mac Book Pro; AFS and network settings? - sshБоковая панель - delphiStrange jQuery AJAX Firefox Issue - The page will not accidentally end Loading - jqueryHow to prevent scrolling in Refresh in a PropertyGrid? - c #Improved TreeView for Windows Forms-.NET 3.5 - .netDo you use HtmlEncode during input or output? - securityConvert this circuit function to another form? - schemeWhen is the time to create a second database? - mysqlPDFKit frame available on iPhone OS? - iphoneAll Articles