Activating web feature from event receiver doesn't do anything
-
28-09-2020 - |
Question
I have the following code that should run to automatically disable the Minimal Download Strategy feature when a new site is being provisioned. Unfortunately nothing happens. No errors are captured in logs, and nothing is output to an exception file:
public override void WebProvisioned(SPWebEventProperties properties)
{
//base.WebProvisioned(properties);
using(SPWeb web = properties.Web)
{
try
{
Guid mdsGuid = new Guid("87294c72-f260-42f3-a41b-981a2ffce37a");
// also tried with SPFeature
SPFeatureCollection mdsFeature = web.Features;
if (mdsFeature[mdsGuid] != null)
{
// tried this with .Remove(mdsGuid, false) as well
web.Features.Remove(mdsGuid);
web.Update();
}
}
catch(Exception ex)
{
using (System.IO.StreamWriter file = new System.IO.StreamWriter("s:\\exceptions\\fail-" + DateTime.Today + ".txt", false))
{
file.WriteLine(ex);
file.Close();
}
}
}
}
Any ideas why this wouldn't run?
Solution
I tried your code and it couldn't find that feature with the provided Guid. So I set this property and it worked:
web.EnableMinimalDownload = false;
web.Update()
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange