Long-time readers of this blog might recall that I have been fairly vocal in my belief that Sitefinity should have a better solution for document & file management. Long-time readers of this blog might also note that they do not, in fact, exist and swiftly disappear in a poof of self-unrealization. (Yes, a similar line exists in Hitchhiker's Guide to the Galaxy. It was funny then and it's funny now! Leave me alone.)
For everyone else, you can read my insightful diatribes on this subject:
Here, Here, and Here.
The Problem
I have a Corporate Intranet that I'm redesigning with Sitefinity that is jam packed with PDFs, Word documents, PowerPoint presentations, Excel files, etc. We're talking hundreds & hundreds of documents. I want these documents to be managed by normal users. Based on past experience I believe strongly that normal users are incapable of dealing with file management. Which means giving users a folder to upload stuff into and then trusting them to set their links correctly will end very poorly.
I also want the documents to be organized within the native Sitefinity "Site Map". This Site Map is elegant and makes the organization of the web site self evident. Which means I don't want to create a Sitefinity module. Doing this would separate the organization of these documents from the native Site Map.
The Solution
I wrote in a previous article how I would like to be able to use custom Sitefinity "Page Types" to solve this problem. This may or may not be something Telerik makes available someday. For now, I needed to solve this problem with the framework currently available to me.
I created a new Sitefinity control called "Document". You can drag & drop this control onto any Sitefinity page. Once placed, you can click Edit and be presented with a Custom Control Designer. This Control Designer will let you upload a file. This file could be anything (a PDF, a Word document, an Excel file, a JPEG, etc).
Once uploaded the Control Designer handles saving the file to the web site and creates a unique file name. The file name & file location get saved as properties of the "Document" control.
As long as you are in "Page Edit" mode this Document control doesn't really do anything except give you a chance to upload a file. If you access the page for real, however, the control swings into action and redirects to the uploaded file.
Check out this link to see this Document control in action.
Before you click, hover your mouse over the link and look at the URL. That is an actual Sitefinity page. Once you click the page the Document control will do a Response.Redirect() to the actual document file.
In the end, I suppose you could say "All this for a redirect?". To which I would reply "Yeah, all of this for a redirect". It works better than you might imagine.
This control lets users upload documents without doing any file management. The control also lets the documents be organized within the native Sitefinity "Site Map". You can even make use of the "History" feature of Sitefinity with this control. Old files never get removed, rather newer files just get a new file name and a new reference. I even altered my "Links" control so that pages with a "Document" control open in a new window.
The unique file names are based on system ticks. I'm also storing files in subdirectories so that the file index doesn't become too large.
How to Download
I have added this control to the GoonDocks Sitefinity Controls.