Tagged: File Upload and Download

0

JumpStart # 42 – Download file in ASP.Net MVC

In this jumpstart, we are going to see how to download a file from server to client browser in ASP.Net MVC using a RouteHandler . A RouteHandler will be created to handle all the requests made to a particular URL with specific route data (part of URL itself) to identify the file requested and will return a particular HttpHandler for the request. HttpHandler is going to find the file on the server, set it into the Response of HttpContext and finally send the response back to the client (typically a browser, but it can be anything).

9

File Upload using MultipartFormDataStreamProvider in ASP.Net WebAPI

In this short tutorial, we are going to see how to upload multiple files using MultipartFormDataStreamProvider in ASP.Net WebAPI. The concept is based on Multipart/form-data in which we can POST not only multiple file contents but also regular form fields which will be available as NameValueCollection on server side.In this tutorial we also see how to override the default behavior of MultipartFormDataStreamProvider which stores the name in a unique BodyPart_{GUID} format to much more meaningful name. We will also invoke our WebAPI using Fiddler to POST file data. Alongside we develop a sample console application which will POST file data using HttpClient class.

31

Retrieve files from a table in Database using Generic Handler

In the first part of this tutorial (PART I – Click Here), we uploaded files to the database in binary format using a FileUpload control. The plot behind saving files is to take the file from the FileUpload control, convert the same to the binary format, then save it to the DB. To make our accomplishment more flexible and maintainable, we use stored procedures along with custom classes for database transactions.

In this part of the tutorial, we retrieve the files (which are stored in a table of a database). For this purpose we first create a custom class which will hold the code for database transactions, then we create a generic handler which will process all the incoming requests for the downloading of files. Finally we create a web page which uses the before mentioned class and handler along with a repeater control to make the file available to the client.

14

Save files to a table in Database using FileUpload control

In this tutorial, we first save files to the database in binary format, then in the second part of the tutorial we see how to provide a download option to the files residing in database. For uploading the files to DB, we use a FileUpload control and to provide download facility we make use of a Generic handler. The plot behind saving files is to take the file from the FileUpload control, convert the same to the binary format, then save it to the DB. To make our accomplishment more flexible and maintainable, we use stored procedures along with custom classes for database transactions. And the plot behind retrieving files is to use a handler which process the incoming request which are made to the files in database.

19

How to download files from server to client using a Generic Handler

In this article, we see how to provide a download option (say for example to download images) to the users of our website. In accomplishing the requirement we use a Generic HttpHandler – which handles all the requests made for the download. For demonstration purpose we take some images and display them using a Datalist, in which we do provide an option to download. On download option click, the generic handler will process the request and displays an dialog in the client questioning client either to save or open the file, accordingly corresponding action will be taken place.