I recently had to modify a feature which had provisioned some stylesheets and images to the style library. One of the things I had to do was remove all the provisioned files and folders when the feature was deactivated.
Amongst others a folder within IMAGES had to be removed in an feature-receiver during FeatureDeactivating. To do this I followed the next steps:
1.
First I got a reference to the Style Library:
SPWeb rootWeb = ((SPSite)properties.Feature.Parent).RootWeb;
SPList styleLibrary = rootWeb.Lists["Style Library"];
2.
Next I had to get a reference tot the IMAGES folder. There probably are more ways to do this, but what I did was loop through the folders until I found the IMAGES folder:
foreach (SPFolder folder in styleLibrary.RootFolder.SubFolders)
{
if (folder.Name.Equals("Images", StringComparison.OrdinalIgnoreCase))
{
}
}
3.
Now, last-but-not-least, in the above if statement you should find the folder you're looking for and delete it:
for(int i = 0; i < folder.SubFolders.Count; i++)
{
if(folder.SubFolders[i].Name.Equals("MyFolder", StringComparison.OrdinalIgnoreCase))
{
folder.SubFolders[i].Delete();
}
}
Abonneren op:
Reacties plaatsen (Atom)
0 reacties:
Een reactie plaatsen