[. ashx files? Generic handler? ] Basic Getting Started #5....ado.net and restoring binary images inside db (sample download & ImageField for large controls)
Http://www.dotblogs.com.tw/mis2000lab/archive/2014/05/19/ashx_beginner_05_db_picture_show_download.aspx
According to the teachings of the previous three articles
You can do it when you are done (you must follow the order, not just to copy it)
- [. ashx files? Generic handler? ] Basics .... Can you teach me in Chinese? Don't talk about Martian text?
- [. ashx files? Generic handler? ] Basic Primer #2....fileupload preview Pictures before uploading (two ways to--ashx and JavaScript)
- [. ashx files? Generic handler? ] Basic Primer #3....ado.net and restoring binary images inside the DB
This article is an example of the ch.18 FileUpload of the book "Last episode"
ASP. 4.5 Thematic Practice (I) , Song Kong Publishing
Method One!
I personally suggest that " when the file is uploaded, there is a Web Server hard disk , the path and file name, put into the DB", this is the simplest!
You can do it without learning new tricks.
My book (last episode) FileUpload is also an introduction to this practice, and there is a complete example in the book.
Method Two! This article will introduce the ...
If you insist on keeping the "file" in your data sheet , you will meet two levels
2-1. How to put the binary IO Stream of the image (file ) into the field of the data table (please set the image data type)
2-2. How do I remove the "binary" data from the data sheet (read it out) and restore it to a picture? Show on the web?
Instructional film: http://youtu.be/JfZ3rYchlLo
In accordance with the third article above, I provide hyperlinks. There's a lot of seniors sharing their program code.
Look at which one is OK, you do it, you can do it.
Related articles such as the following, any choice of one can be completed:
Microsoft MSDN example is there, See HTTP://MSDN.MICROSOFT.COM/ZH-TW/LIBRARY/SYSTEM.W Eb.ui.webcontrols.fileupload.postedfile (v=vs.110). aspx
Http://www.cnblogs.com/travelcai/archive/2007/09/27/907203.html
http://davidma168.wordpress.com/2011/01/25/ashx-%E8%BC%B8%E5%87%BA%E5%9C%96%E7%89%87/
http://davidma168.wordpress.com/2011/01/25/ashx-output-image-2/
- http://4068205.blog.51cto.com/4058205/1090928 Recommended!
- http://www.dotblogs.com.tw/ligthwaver/archive/2011/09/21/37066.aspx Simple!
- http://welkingunther.pixnet.net/blog/post/25986417-(ASP)%e7%94%a8http-handler%e6%8a%8a%e8%b3%87%e6%96%99% E5%ba%ab%e7%9a%84%e4%ba%8c%e9%80%b2%e4%bd%8d%e5%9c%96%e7%89%87%e6%aa%94%e9%a1%af
- Http://www.soaspx.com/dotnet/asp.net/tech/tech_20100204_2767.html
===============================================================================================
First, create a data table
To store the "Pictures, files" field, please set the image data type
Another field, to set the MIME format , is usually to put the file name (extension) in. In the future, these binary data will be left alone, combined into the original picture, the use of mime!
Examples of data tables can be downloaded from this (. sql file with the name image)
https://onedrive.live.com/?cid=6F7F668080F24B20&id=6F7F668080F24B20%21115
Second, upload the example, you can see the FileUpload program some changes
2-1. No need for archiving
FileUpload's . The SaveAs () method is not available . Because the file is uploaded and then written to the data table, the WEB server hard disk is not present
You do not have to set the directory, path
2-2. after uploading, the IO stream of the archive (image) is read in a " Byte array " manner
The contents of this byte array (binary data of the image) can be stored in the data table.
Third, the picture in the DB (binary) restore, show on the page
I've used two methods here, but the principle is the same.
In short, the action of reading and restoring images is placed in the. ASHX Program
3-1. Generic Image Control
<asp:image Id= "Image1" runat= "Server"
imageurl=' <%# ' fileupload_db_image_02_displayashxid= "+ Eval (" fileupload_db_id ")%> '/ >
3-2. Image field template fields in large controls
<asp:gridview,,,,, >
<asp: ImageField dataimageurlfield= "fileupload_db_id (the domain name of the data table!) )"
dataimageurlFormatString= "Fileupload_db_image_02_display. ashx? id={0}" >
</asp:ImageField>
</asp:Gridview>
Finally, read the picture (from the database). Revert to the original MIME format of the image, all using the ashx program to do
This series of examples, is not the introduction of ASHX?
Looking back at the first step, our FILEUPLOAD_DB2 data sheet, more design two "fields",
one holds "picture (binary)", the other one holds "extension" as MIME
............ The principle is not very clear?
===============================================================================================
File Download:
Because these examples are also learned on the web
Seniors are willing to share, I am ready to share (remember to match the first step, first set your fileupload_db2 Data Sheet to complete)
Ashx_cs.rar Ashx_vb.rar
Knowledge because of sharing and great
The "large volume" of pictures, files in the Data table "field", there will be some defects
These points will be reported to you during the class.
You can also refer to SQL FileStreamand try to understand why these improvements are available.
Where is the improvement? ...... The following is a description of the MSDN Web site
FILESTREAM allows SQL Server schema applications to store unstructured data, such as files and images , on a file system. Applications can leverage the rich data flow APIs and performance of file systems while maintaining transactional consistency between unstructured data and corresponding structured data.
FILESTREAM consolidates SQL Server Database Engine with the NTFS file system by combining varbinary (max) binary Large Objects (BLOBs) /c3> data is stored on the file system as an archive. Transact-SQL statements can insert, UPDATE, query, search, and back up FILESTREAM data. The Win32 file system interface provides data flow mode access.
FILESTREAM uses NT system cache to store archival data. This reduces any impact that FILESTREAM data may have on Database Engine performance. The SQL Server buffer pool is not used, so this memory can be used for query processing.
When you install or upgrade SQL Server, FILESTREAM is not automatically enabled. You must use SQL Server configuration Administrator and SQL Server Management Studio to enable FILESTREAM. To use FILESTREAM, you must establish or modify the database to contain special types of file groups. Then, create or modify the data table to contain the varbinary (max) data row that has the FILESTREAM property. Once you have completed these tasks, you can use Transact-SQL and WIN32 to manage FILESTREAM data.
If you want to upload an image, you also want to "thumbnail"
FileUpload after, thumbnail (large map to small map)
Search keywords "asp.net thumbnail" can find many examples, you can refer to these articles, it is clear:
Http://wangshifuola.blogspot.tw/2011/10/aspnetimage-resize.html
Http://demo.tc/Post/95
http://blog.xuite.net/cppbuilder/blog/9331487