Friday, September 4, 2015

Removing orphaned resources left by Sandboxed Solutions

I recently experimented with a Sandboxed Solution to insert some javascript files into all pages of a site collection.  This worked quite well, even to the point of the files continuing to be requested by the pages after the solution was removed and deleted.

I finally grew tired of the multiple unnecessary 404 errors being generated on the page views of the site collection.  I'd spent a fair bit of time looking for how to remove the orphaned items before I opened MS case.

Eventually we discovered the solution and again it was quite easy once we knew what to do.

For some background, here's the Elements.xml of the Sandboxed Solution:


 
   
   
   
   
   
 

      ScriptSrc="~sitecollection/SiteAssets/js-class.js"
    Location="ScriptLink"
    Sequence="105">
 

      ScriptSrc="~sitecollection/SiteAssets/bluff-min.js"
    Location="ScriptLink"
    Sequence="110">
 

      ScriptSrc="~sitecollection/SiteAssets/jquery.min.js"
    Location="ScriptLink"
    Sequence="100">
 
To remove these orphaned files I used powershell:
$s = get-spsite https://foo.com 
$uca = s.UserCustomActions | select -first 1 
$uca  # Visually validate this one to delete before running the next command 
$uca.delete()

No comments: