Using uploadify in ASP.Net MVC application

Dropbox is getting more and more popular. I use it on my desktop, laptop, iphone, and ipad. Once I went to a post office to post a document, and realised that I don't know the address. I had my iphone with me, so used Dropbox to get the address. It was so useful, and ever since, I became a fan of Dropbox.

Anyway, Dropbox has nice Flash-based upload functionality, and I wanted to mimic the feature in my application. SlickUpload is a very good component, but commercial. I googled and came across uploadify.

The site has good example code and a link to example too. If you want to make your file upload testable, read Scott hanselman's fantastic post about it.

The below is my code. One thing to note in the code are

[sourcecode language="csharp"]
public ActionResult UploadFiles()
foreach (string file in Request.Files)
var postedFileBase = Request.Files[file];
if (postedFileBase.ContentLength == 0)

string savedFilename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,

return View();


[sourcecode language="javascript"]
'uploader': '<%= Url.SiteRoot() %>/public/images/uploadify.swf',
'script': 'Home/UploadFiles',
'cancelImg': '<%= Url.SiteRoot() %>/public/images/cancel.png',
'auto': false,
'multi': false

<h2>Simple file upload.</h2>

<form action="<%= Url.Action("UploadFiles", "Home") %>" method="post" enctype="multipart/form-data">

<input type="file" name="file" id="file" />
<a href="javascript:$('#file').uploadifyUpload();">Upload Files</a>