Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It depends on where you want to execute your code. If you have a sharepoint context then you can use </p> <pre><code>SPWeb oWebsite = SPContext.Current.Web; oWebsite.Features.Add(new Guid({guid of feature})); </code></pre> <p>or</p> <pre><code>using(SPWeb oWebsite = SPContext.Current.Site.OpenWeb("Website_URL")) { oWebsite.Features.Add(new Guid({guid of feature})); } </code></pre> <p>If you were using a console app for example, and didn't have an SPContext you could use</p> <pre><code>using(SPSite oSiteCollection = new SPSite("http://Server_Name")) { using(SPWeb oWebsite = oSiteCollection.OpenWeb("Website_URL")) { oWebsite.Features.Add(new Guid({guid of feature})); } } </code></pre> <p>There are lots of other ways to get hold of an SPWeb object, but it depends on what information you have about the site (name, url, position in the heirarchy)</p> <p>If you want to activate a feature that is scoped against a Site Collection or Web Application, then you can get hold of the SPSite or SPWebApplication in a similar manner.</p> <p>SPSite:</p> <pre><code>SPContext.Current.Site </code></pre> <p>or</p> <pre><code>SPSite oSiteCollection = new SPSite("Absolute_URL") </code></pre> <p>SPWebApplication:</p> <pre><code>SPContext.Current.Site.WebApplication </code></pre> <p>or</p> <pre><code>SPWebApplication.Lookup(new Uri("http://MyServer:989")); </code></pre> <p>and on either of these objects, you can call </p> <pre><code>object.Features.Add(...)) </code></pre> <p>In the same way as the above code.</p> <p>Note: The scope of the feature is specified in the feature.xml, see the following for details: <a href="http://msdn.microsoft.com/en-us/library/ms436075.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms436075.aspx</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload