停用 sharepoint 中的 Web 部件功能

发布于 2024-09-17 08:57:17 字数 234 浏览 3 评论 0原文

我使用 wspbuilder 工具(具有功能的 Web 部件)开发了一个 Web 部件。

部署(到网站集)时,您必须激活该功能才能使用此 Web 部件 - 到目前为止一切顺利。

但是,当停用该功能时,Web 部件仍保留在添加它的任何网站上,而且它仍然在 Web 部件库中可用?

这是预期的行为吗?是否无法从网站集中的所有子网站中删除 Web 部件,并从 Web 部件库中删除它?

谢谢 ;)

I've developed a web part using the wspbuilder tool (Web part with feature).

When deployed (to a site collection), you have to activate the feature in order to use this web part - so far so good.

However, when deactivating the feature, the web part remains on any site where it's been added, and furthermore, it's still available in the web part gallery?

Is this expected behaviour? Is there no way of removing the web part from all subsites in the site collection, and also remove it from the web part gallery?

Thanks ;)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

戏舞 2024-09-24 08:57:17

这是预期的行为。您可以自动删除它,但您必须编写一个功能接收器来完成此操作。

有关为 SharePoint 2007 创建功能接收器的详细信息:
http://sharepointdevwiki.com/显示/公共/如何+添加+a+功能+接收器+to+a+功能

This is expected behavior. You could remove it automatically, but you would have to write a feature receiver to accomplish that.

More info about creating a feature receiver for SharePoint 2007:
http://sharepointdevwiki.com/display/public/How+to+add+a+Feature+Receiver+to+a+Feature

俏︾媚 2024-09-24 08:57:17

当您创建 Web 部件时,WSPBuilder 会自动将删除事件接收器添加到功能中。非常方便。

WSPBuilder automatically adds the removal event receiver to the feature when you create a web part. Very convenient.

月光色 2024-09-24 08:57:17

您可以使用以下代码来完成此操作:

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
    SPSite site = properties.Feature.Parent as SPSite;

    if (site != null)
    {
        try
        {
            SPList wpGallery = site.GetCatalog(SPListTemplateType.WebPartCatalog);
            SPQuery query = new SPQuery();
            query.Query = “<Where><Eq><FieldRef Name=’FileLeafRef’ /><Value Type=’Text’>webpartname.webpart</Value></Eq></Where>”;
            SPListItemCollection items = wpGallery.GetItems(query);

            if (items.Count > 0)
            {
                items[0].Delete();
            }
        }
        catch { }
    }
}

You can do it by using the following code:

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
    SPSite site = properties.Feature.Parent as SPSite;

    if (site != null)
    {
        try
        {
            SPList wpGallery = site.GetCatalog(SPListTemplateType.WebPartCatalog);
            SPQuery query = new SPQuery();
            query.Query = “<Where><Eq><FieldRef Name=’FileLeafRef’ /><Value Type=’Text’>webpartname.webpart</Value></Eq></Where>”;
            SPListItemCollection items = wpGallery.GetItems(query);

            if (items.Count > 0)
            {
                items[0].Delete();
            }
        }
        catch { }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文