0

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?

3
  • Does it definitely hit the web.update()? Commented Jun 2, 2014 at 23:01
  • Yeah it hits web.Update() but nothing happens.
    – psdpainter
    Commented Jun 3, 2014 at 14:56
  • I'll test your code. Commented Jun 3, 2014 at 15:02

1 Answer 1

1

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()
6
  • Do you need to call web.Update() after or does it work with just that?
    – psdpainter
    Commented Jun 3, 2014 at 15:13
  • Yes. Always call update() or your changes will not be committed Commented Jun 3, 2014 at 15:16
  • Trying it right now
    – psdpainter
    Commented Jun 3, 2014 at 15:21
  • Thanks Colbs. Just had to do 3 iisresets for it to kick in.
    – psdpainter
    Commented Jun 3, 2014 at 15:45
  • haha. 3rd time's a charm. yw Commented Jun 3, 2014 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.