I’m trying to deploy a selection of features and to do this I need to select the target site and then use:
objWeb.Features.Add(new Guid({guid of feature}));
my question is how would I select this site, all the help i’ve found creates the site using its constructor and then keeps track of it, where as I want to open an existing one.
Thank you.
It depends on where you want to execute your code. If you have a sharepoint context then you can use
or
If you were using a console app for example, and didn’t have an SPContext you could use
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)
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.
SPSite:
or
SPWebApplication:
or
and on either of these objects, you can call
In the same way as the above code.
Note: The scope of the feature is specified in the feature.xml, see the following for details:
http://msdn.microsoft.com/en-us/library/ms436075.aspx