Minggu, 10 Januari 2010

File Upload and download

For this commodity I would like to extend bit added to add some angel examination adequacy to the GridView application HttpHandler. The afterward is the ambition of this article.

1) ASP.Net File Upload to upload the angel to the web server

2) Apprehend it as a byte arrangement and don’t save it to the book system

3) Amend the byte arrangement to save it to the database

4) Load the filigree with angel ascendancy and advertence the angel aisle to a HttpHandler

5) Develop the HttpHandler to apprehend the abstracts into a byte array

6) In HttpHandler cede the abstracts as angel and set the agreeable blazon as image

Asp.Net Book Upload to upload file

The file download abstracts can be calmly accessed application the article PostedFile, if you appetite to save use the PostedFile.SaveAs () adjustment to save to a book system. But our ambition is to save it to a DB so we aloof admission the byte arrangement into a capricious and advance it to database later.

As explained beforehand the Book Upload is activity to be in the GridView. And the file upload called book has to be uploaded to the web server application a PostBack. So we use a abide button forth with the in the ItemTemplate. (For added advice apropos base command to the buttons in the ItemTemplate, apprehend actuality Asp .net GridView with templates)

Fetch abstracts from Book Upload Ascendancy into a byte array

In the RowCommand accident of the GridView afterwards the CommandName is verified, the Command altercation can be acclimated to back the accepted row (based on the acceptance that the command altercation is apprenticed with the Container.DataItemIndex in the markup).

Once the row is accessible use the FindControl to get the FileUpload, PostedFile article has an InputStream, with that the byte arrangement can be busy with the uploaded file.

Update the Database with byte array

We are application Northwind Database for the sample, this time we accept taken the advisers table. Basically the amend concern will be

Update Advisers set Photo=@Photo area EmployeeId=@EmployeeId

So we charge two SqlParameters to canyon the Agent id and the byte array. Byte arrangement we accept aloof apparent how to back it and the agent id can be taken from the Datakeys

Tidak ada komentar:

Posting Komentar