ASP.NET File Uploading

After some theory, this article will present a file upload and download utility you can use to manage files on your server. You can download all of the files for this article, including the image files...

File upload and download are much simpler tasks in ASP.NET than in classic ASP, thanks to the extensive .NET Framework class library. File upload in ASP.NET is as easy as retrieving an HTML form value. In classic ASP, it's a somewhat involved process, in which you have to extract the content of the uploaded file from raw HTTP request data. In the end, many ASP programmers resort to a third-party component for file upload.

File download is even easier in ASP.NET with the new WriteFile method in the Request object. Sending a file to the browser can be achieved using a single line of code. In classic ASP, you have to open the file yourself and send a number of bytes at a time. With file download, however, the same problem remains as in classic ASP and other Web technologies. Many Web programmers still wonder how they can force the browser to display the Download dialog. Sending the file with the WriteFile method will not necessarily display the dialog. The default behavior for browsers is that if the file's MIME type is recognized, the browser will either try to display the content or it will fire up an application associated with that MIME type. This "smart" behavior is often not the desired behavior. In this article, I will show you how to force the browser to always show the Download dialog, so the user can save the file to disk.

Chris Charlton

Chris CharltonChris, Los Angeles' CSS & ActionScript guru, successfully cannonballed into web development in the late 90's. Always caught up with the latest in Flash, Dreamweaver, Fireworks, and XML, Chris authored premium articles for the largest Dreamweaver/Flash community (www.DMXzone.com) and produced WebDevDesign (iTunes featured), a popular Web Design & Development Podcast. Somewhere, Chris finds time to run an authorized Adobe user group focused around open source and Adobe technologies. Being a big community leader, Chris Charlton remains a resident faculty member of the Rich Media Insitute and lends himself to speak at large industry events, like JobStock, NAB, and FITC Hollywood.

Brain cycles from Chris are always Web Standards, Flash Platform, and accessibility.

See All Postings From Chris Charlton >>

Comments

Be the first to write a comment

You must me logged in to write a comment.