SP2010: Cannot delete folder in FeatureUninstalling method

Posted on 2012-09-21
Last Modified: 2012-10-03
Hello. I would like to remove folder when my webpart is uninstalled. Unfortunately this code does not work -> object is null exeption. What am I doing wrong? Code (spcontext.current.web) do work when used in FeatureDeactivating method (user deactivates feature manually).

                    SPSite siteCollection = properties.Feature.Parent as SPSite;

                    if (siteCollection != null) 
                        SPWeb web = siteCollection.RootWeb;
                        web.Folders["Style Library"].SubFolders["myfolder"].Delete();

Open in new window

Question by:tolppa
    1 Comment
    LVL 11

    Accepted Solution

    Please try this :

    The URL should be like this: "Style Library/myfolder"

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Note:  There are two main ways to deploy InfoPath forms:  Server-side and directly through the SharePoint site.  Deploying a server-side InfoPath form means the form is approved by the Administrator, thus allowing greater functionality in the form. …
    For SharePoint sites, particularly public-facing ones, there are times when adding JavaScript, Meta Tags, CSS Styles or other content to the page <head> section is more practical than modifying master pages.  For instance, you could add the jQuery l…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now