SharePoint 2007 将 MasterPage 部署为功能删除停用时的文件

发布于 2024-09-08 05:08:12 字数 276 浏览 2 评论 0原文

我有一个 MasterPage,正在部署到 SharePoint 2007 服务器。我正在使用一个功能和一个 wsp 来进行部署。部署后,我的网站无法选择和使用新的母版页。然后,如果我激活我的功能,我就可以选择我的母版页。但是,当我停用我的功能(甚至撤回解决方案并将其从 SharePoint 中删除)时,母版页仍然可供选择,并且属于我的功能/解决方案的所有其他文件仍然位于 SharePoint 上。那么,有什么方法可以在我的功能停用时删除母版页的可用状态,然后如果它再次激活,它是否再次可用?

希望这是有道理的,谢谢。

I have a MasterPage that I am deploying to a SharePoint 2007 server. I am using a feature and a wsp to do the deployment. After deployment, my new masterpage isn't available to select and use for my site. Then, if I activate my feature, I am able to select my master page. But, when I deactivate my feature (or even retract the solution and delete it from SharePoint), the master page is still available for selection and all of the other files that were part of my feature/solution are still on SharePoint. So, is there any way to remove the master page from being available when my feature is deactivated, and then if it gets activated again, have it be available again?

Hope this makes sense, thanks.

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

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

发布评论

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

评论(2

陌上青苔 2024-09-15 05:08:12

默认情况下,SharePoint 不会清理作为功能激活的一部分部署的文件。

为了删除母版页和其他关联文件,您需要为您的功能编写功能接收器,实现FeatureDeactivating 方法,并使用对象模型代码而不是CAML 删除文件。功能接收器的 MSDN 文档位于此处,并且有编写功能接收器代码的博客示例 整个网络

请记住,为了删除母版页,您首先需要确保将网站集中所有网站的母版页重置为默认/另一个可用的母版页。您还需要小心,不要删除母版页或页面布局之间共享的资源文件(CSS、图像等)。

SharePoint doesn't by default clean up files deployed as part of a feature activation.

In order to remove the master page and other associated files you'll need to write a feature receiver for your feature, implement the FeatureDeactivating method, and remove your files using object model code instead of CAML. MSDN document for feature receivers is here, and there are blog examples of writing feature receiver code all over the web.

Bear in mind that in order to remove your master page you'll first need to make sure you reset the master page for all sites in the site collection to the default/another available master page. You'll also want to be careful not to remove resource files (CSS, images, etc.) that are shared among master pages or page layouts.

绝不放开 2024-09-15 05:08:12

首先确保您在停用功能时不再使用母版页。然后您可以将其删除。

SPWeb web = (SPWeb)properties.Feature.Parent;

string customMasterUrl = (new Uri(web.Url + "/_catalogs/masterpage/Sample.master")).AbsolutePath;

if (web.MasterUrl != customMasterUrl)
{
  try
  {
    SPFile file = web.GetFile(customMasterUrl);
    SPFolder masterPageGallery = file.ParentFolder;

    SPFolder temp = masterPageGallery.SubFolders.Add("Temp");
    file.MoveTo(temp.Url + "/" + file.Name);
    temp.Delete();
  }
  catch (ArgumentException)
  {
    return;
  }
}

First make sure you are not using the Master page anymore in the feature deactivating. Then you can remove it.

SPWeb web = (SPWeb)properties.Feature.Parent;

string customMasterUrl = (new Uri(web.Url + "/_catalogs/masterpage/Sample.master")).AbsolutePath;

if (web.MasterUrl != customMasterUrl)
{
  try
  {
    SPFile file = web.GetFile(customMasterUrl);
    SPFolder masterPageGallery = file.ParentFolder;

    SPFolder temp = masterPageGallery.SubFolders.Add("Temp");
    file.MoveTo(temp.Url + "/" + file.Name);
    temp.Delete();
  }
  catch (ArgumentException)
  {
    return;
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文