Reza on blogging [MVP]

THIS BLOG HAS MOVED TO: http://blogs.devhorizon.com/reza

Subscriptions

<January 2009>
SuMoTuWeThFrSa
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

News



toronto.sharepoint.camp


Navigation

Post Categories

Other Bloggers

Personal Links

Saturday, November 25, 2006 - Posts

The beauty of using SPWeb in conjunction with the SPSite constructor

I have been using SPSite and SPWeb classes for a long time to retrieve information from SharePoint. I think for security reason the entry point from outside to a site is ONLY available through the site collection to which that site belongs to. In another word, if you need to retrieve a SPWeb instance for a subsite, you cannot use the following statement:

SPWeb myWeb = new SPWeb ("http://Server_Name/sites/HR/Candidates/default.aspx");

Instead you should use something like this:

SPSite siteCollection = new SPSite ("http://Server_Name/sites/HR/Candidates/default.aspx");
SPWeb site = siteCollection.OpenWeb(); <-- You will get an SPWeb object representing Candidates subsite

It is nice, isn't it?

You specify your FULL subsite URL in site collection and you end up getting the SPWeb object representing your subsite in the second line. Yes, SPSite and SPWeb are smart enough to return the lowest-level site specified by the URL that is passed as parameter for the constructor of SPSite. Remember that SPSite still refer to the top-level site which in this case is http://Server_Name/sites/HR.


posted Saturday, November 25, 2006 1:34 AM by admin with 0 Comments

Powered by Community Server, by Telligent Systems