File uploading has been a hot topic during my time as an internet programmer. In the classic ASP days this was a bit of a task to build and get correct. Nowadays both Adobe’s Coldfusion and Microsoft’s ASP.NET both have built in file uploader tags ( server controls ) that handle this with ease.
This is great, but what happens when you have a mixed bag of clients that all need to upload to the same location? Sometimes I work with completely ASP.NET or CF web apps, but more often than not I’m dealing with Flash clients as well as HTML clients.
Recently I ran into this upload scenario and built this simple ASP.NET uploader script. This feels a bit old school since it uses .NET’s built in Request.Files collection, instead of a fancy new ‘all in one’ server control, but I actually prefer this method.
Here’s all you need :
// Check for posted files
for (int xx = 0; xx < Request.Files.Count; xx++)
{
// UPLOAD FILE
HttpPostedFile _file = Request.Files[xx];
// create full save path for uploaded file
var full_file_path = Server.MapPath( UP_FOLDER ) + "\\" + _file.FileName;
try
{
// save file to server
_file.SaveAs(full_file_path);
}
catch (Exception exc)
{
var emsg = "Unable to upload file : " + exc.Message;
Response.Write( emsg );
Response.Flush();
Response.End();
}
// show result
Response.Write( _file.FileName + " uploaded! <br>" );
}
That’s all there is to it codewise. Before using this code you will need to give the NETWORK SERVICES user write permissions to your upload folder. Other than that, that’s all she wrote!
Here is a zip of all the code for you to download.
Inside this zip you will find :
- flashclient.fla – Flash upload client ( *be sure to update the upload path before building )
- flexclient.mxml – Flex upload client ( *also update upload path before building )
- uploader.aspx - ASP.NET file upload handler
- uploadform.html - sample HTML upload form ( again, update path )
Hope somebody finds this useful.










