开发者

SharePoint 2010 Delete files/folders with PowerShell

I have created a customized master page using Visual Studio 2010 by way of a module that has a 开发者_开发知识库feature in it that contains all my customizations, css, images and master page. When I deploy the solution the first time no worries everything works great, when I deploy it the second time I get an error saying a file specified in the module already exists. So I have to now open up SPD and delete all the files, I also have to change the masterpage page back to the v4.master page before I can delete the files. I found a way to reset the masterpage with PowerShell and the next step would be to delete the remaining files and folders so its a nice neat package. I would love to be able to do it all from my Feature deactivation script that is currently written in C#, but that does not seem to actually retract the items.

This is how I am currently trying to deactivate the feature:

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
    {
        SPSite curSite = (SPSite)properties.Feature.Parent;
        SPWeb curWeb = curSite.RootWeb;
        //Create full master url
        Uri masterUri = new Uri(curWeb.Url + "/_catalogs/masterpage/corporate.master");
        //master page used by all publishing pages on the site
        curWeb.CustomMasterUrl = masterUri.AbsolutePath;
        curWeb.Update();
     }

Thanks


PowerShell:

remove-Item 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\IMAGES\your images' -recurse -Force

remove-Item 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\your master page.master' -Recurse -Force

remove-Item 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\1036\STYLES\yourcss.css' -Recurse -Force


Set the flag IgnoreIfAlreadyExists="true" on your -tag in your module and you should be fine. See http://msdn.microsoft.com/en-us/library/ms459213.aspx and http://www.sharepointvoodoomagic.com/2009/01/ignoreifalreadyexists.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜