我想部署一个选择的功能,并要做到这一点,我需要选择目标站点,然后使用:部署功能单一的SharePoint网站/如何选择一个SharePoint网站
objWeb。 Features.Add(新的Guid({guid of feature}));
我的问题是我怎么会选择这个网站,所有我已经找到了帮助创建使用其构造的网站,然后跟踪它,在这里,我想打开一个现有的。
谢谢。
我想部署一个选择的功能,并要做到这一点,我需要选择目标站点,然后使用:部署功能单一的SharePoint网站/如何选择一个SharePoint网站
objWeb。 Features.Add(新的Guid({guid of feature}));
我的问题是我怎么会选择这个网站,所有我已经找到了帮助创建使用其构造的网站,然后跟踪它,在这里,我想打开一个现有的。
谢谢。
这取决于你想要执行你的代码的地方。如果你有一个SharePoint上下文,那么你可以使用
SPWeb oWebsite = SPContext.Current.Web;
oWebsite.Features.Add(new Guid({guid of feature}));
或
using(SPWeb oWebsite = SPContext.Current.Site.OpenWeb("Website_URL"))
{
oWebsite.Features.Add(new Guid({guid of feature}));
}
如果您正在使用例如控制台应用程序,并没有一个SPContext你可以使用
using(SPSite oSiteCollection = new SPSite("http://Server_Name"))
{
using(SPWeb oWebsite = oSiteCollection.OpenWeb("Website_URL"))
{
oWebsite.Features.Add(new Guid({guid of feature}));
}
}
有很多其他的方法来获得一个SPWeb对象,但它取决于你有什么关于该网站的信息(名称,url,在heirarchy中的位置)
如果要激活针对网站集或Web应用程序作用域的功能,则可以用类似的方式获取SPSite或SPWebApplication。
的SPSite:
SPContext.Current.Site
或
SPSite oSiteCollection = new SPSite("Absolute_URL")
SPWebApplication:
SPContext.Current.Site.WebApplication
或
SPWebApplication.Lookup(new Uri("http://MyServer:989"));
和这些对象中的任何一个,您可以拨打电话
object.Features.Add(...))
与上面的代码一样。
注:该功能的范围在feature.xml规定,详见如下: http://msdn.microsoft.com/en-us/library/ms436075.aspx
对于Web范围的功能使用:
using (SPWeb currentSite = SPContext.Current.Web)
{
currentSite.WebFeatures.Add(new Guid("{GUID}"));
}
对于站点范围的功能使用:
using (SPWeb currentSite = SPContext.Current.Web)
{
currentSite.Features.Add(new Guid("{GUID}"));
}
因此,我有一个webApp http:// test:10413 /要部署到整个应用程序我会将网址传递到sitecollection创建者? – Nath 2009-10-28 15:16:45
您能否澄清该功能的范围(Web应用程序,网站集或网站)?我以为你试图部署到一个单一的网站,但如果你想部署到WebApp,我可以找到一些代码为 – AlexWilson 2009-10-29 08:29:02
我添加了一些例子来激活一个解决方案作用于Web应用程序和网站集合 – AlexWilson 2009-10-29 08:44:20