Tim

Footprints in the snow of a warped mind

Clean out unused media items from Umbraco media folder

Where to find me

Flickr Icon  Twitter Icon  Linked In Icon  FaceBook Icon  Windows Live Alerts Butterfly  RSS 2.0 

Tag Cloud

AJAX (4) ASP (6) ASP.Net (47) Error Reporting (4) Web Service (1) WSDL (1) Atlas (2) Business (74) Business Start-up Advice (25) Client (13) Expanding Your Business (17) C# (15) Canoeing (4) Canoe Racing (5) Cheshire Ring Race (5) Racing (2) Training (4) CIMA (1) Cisco (1) 7970G (1) CSS (3) dasBlog (4) DDD (1) Design (9) Icons (1) Development (11) General (39) Christmas (6) Fun and Games (11) Internet (22) Random (46) RX-8 (8) Home Cinema (2) Hosting (1) IIS (8) iPhone (1) JavaScript (2) Marketing (5) Email (1) Multipack (1) Networking (2) Nintendo (1) OS Commerce (1) Photography (1) PHP (1) PowerShell (1) Press Release (1) Productivity (2) Security (2) SEO (5) Server Maintenance (3) Server Management (8) Social Networking (1) Experiment (1) Software (9) Office (5) Visual Studio (11) Windows (4) Vista (1) SQL (1) SQL Server (13) Stored Procedure (1) Testing (1) The Site Doctor (102) Turnover Challenge (1) Twitter (1) Umbraco (15) 2009 (1) Web Development (50) WebDD (33) Wii (1)

Blog Archive

Search

<March 2010>
SunMonTueWedThuFriSat
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910

Recent Comments

Blog Archive

Various Links

Blogs I Read

[Feed] Google Blog
Official Google Webmaster Central Blog
[Feed] Matt Cutts
Gadgets, Google, and SEO
[Feed] Ol' Deano's Blog
My mate Dean's blog on my space, equally as random as mine but not off on as much of a tangent!
[Feed] Sam's Blog
Sam is one of my younger brothers studying Product Design and Manufacture at Loughborough, this is his blog :) Enjoy!

Recent Tracks

last.fm - The Social Music Revolution

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

newtelligence dasBlog 2.2.8279.16125

Send mail to the author(s) Email Me (Tim Gaunt)

© 2010 Tim Gaunt.

Sign In

    # Wednesday, September 03, 2008

    Clean out unused media items from Umbraco media folder

    Wednesday, September 03, 2008 5:15:14 PM (GMT Daylight Time, UTC+01:00)

    When uploading some new media items for a client today we noticed that if you selected "Remove" before saving, it doesn't actually remove the file from the FileSystem. Having a quick look around the forums I saw there are a few posts already pointing this out so I thought I'd fix it.

    This is a little application that simply checks the media items in the database and then compares it against a folder you select on your machine. If the file is in use according to the database then it's ignored otherwise it will remove it.

    To use:

    1. Enter your server's login details
    2. Click "Test Connection"
    3. Select the relevant database from the drop down
    4. Check the "Media Folder Name" matches your Umbraco's installation
    5. Locate your Media Folder on your computer
    6. Click "Check Media Folder" -this will then list all the orphan files
    7. If it looks right, click "Delete" -with caution
    8. Job done

    There are a few checks in place to avoid mishap but it's not 100% foolproof as I needed something rough and ready to sort a couple of installations out. If this is something that's seen as useful I'll extend it a touch, some ideas I've got already:

    • Check that the selected media folder matches that of the database
    • Check that the media id's are the same (to avoid wiping another installation)
    • Save config settings for easy re-use
    • Use webservices rather than a direct connection to the database
    • Enable FTP useage

    Please note: I accept no responsibility if anything was to go horribly wrong with this. I would backup your folder first just in case!

    You can download the MediaFolderCleaner application here

    Thursday, October 23, 2008 5:46:20 PM (GMT Daylight Time, UTC+01:00)
    Very nice. Any chance of getting the source? I'm mainly interested in your SQL to find out if the file is in use. :-)

    Thanks!
    Tuesday, November 25, 2008 2:18:03 PM (GMT Standard Time, UTC+00:00)
    Hi Mark

    The SQL is actually fairly simple:

    SELECT [content] FROM [umbracoContentData] WHERE [alias] = 'umbracofile' AND [Content] IS NOT NULL

    I'll dig up the source at some point if you like :)

    HTH

    Tim
    Wednesday, January 21, 2009 12:50:35 PM (GMT Standard Time, UTC+00:00)
    I enter the SQL-Server URL and the correct username and password, but the database pull-down is never populated with any databases.

    Am I doing something wrong?

    Thanks in advance!

    /Thomas K
    Thomas Kahn
    Wednesday, January 21, 2009 8:03:05 PM (GMT Standard Time, UTC+00:00)
    Hi Thomas,

    I don't think so, Doug had a similar issue a while ago which I think he sorted. I'll add some debugging info if I get a moment and we'll find out what's going on.

    Tim
    Tuesday, March 24, 2009 11:23:48 AM (GMT Standard Time, UTC+00:00)
    When i select a database i get this error:

    An item with the same key has already been added.
    Dan
    Sunday, April 19, 2009 5:32:52 PM (GMT Daylight Time, UTC+01:00)
    Interesting, thanks for that Dan, without checking I'd hazard a guess at the fact that I'm not clearing the list of database names or something silly like that. I'll look into it and post and update ASAP.

    Tim
    Wednesday, December 02, 2009 7:53:40 AM (GMT Standard Time, UTC+00:00)
    Hi Tim

    Any chance you've fixed the bug in my post above? Or can i get the source code for this project please?

    Thanks

    Dan
    Dan Evans
    Wednesday, December 02, 2009 10:44:28 AM (GMT Standard Time, UTC+00:00)
    I've just updated it, looking at the code that should have only happened if you changed your db string without reloading the form.

    Let me know how you get on

    Tim
    Thursday, December 03, 2009 2:30:53 PM (GMT Standard Time, UTC+00:00)
    I think there is a problem with my DB. Using the SQL above i get some duplicate files (possibly different versions?). Would that be why it's erroring?

    Also, it wants to delete thumbnails when it shouldn't unless the main file isn't used.

    Thanks

    Dan
    Dan Evans
    Name
    E-mail
    (will show your gravatar icon)
    Home page

    Comment (HTML not allowed)  

    Live Comment Preview