Đang chuẩn bị liên kết để tải về tài liệu:
ASP.NET 4 Unleased - p 23

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Chú ý Các thông số kỹ thuật HTML 4.01 xác định một chấp nhận thuộc tính mà bạn có thể sử dụng để lọc các tập tin có thể được tải lên. Thật không may, trình duyệt không hỗ trợ việc chấp nhận các thuộc tính, vì vậy bạn phải thực hiện lọc trên máy chủ (hoặc sử dụng một số JavaScript để kiểm tra phần mở rộng tên tập tin trên máy khách). | 194 CHAPTER 4 Using the Rich Controls LISTING 4.6 FileHandlerLarge.ashx @ WebHandler Language C Class FileHandlerLarge using System using System.Web using System.Data using System.Data.SqlClient public class FileHandlerLarge IHttpHandler const string conString @ Server . SQLExpress Integrated Security True AttachDbFileName DataDirectory FilesDB.mdf User Instance True public void ProcessRequest HttpContext context context.Response.Buffer false context.Response.ContentType application msword SqlConnection con new SqlConnection conString SqlCommand cmd new SqlCommand SELECT FileBytes FROM Files WHERE Id@Id con cmd.Parameters.AddWithValue @Id context.Request Id using con con.Open SqlDataReader reader cmd.ExecuteReader CommandBehavior.SequentialAccess if reader.Read int bufferSize 8040 byte chunk new byte bufferSize long retCount long startIndex 0 retCount reader.GetBytes 0 startIndex chunk 0 bufferSize while retCount bufferSize context.Response.BinaryWrite chunk startIndex bufferSize retCount reader.GetBytes 0 startIndex chunk 0 bufferSize From the Library of Wow eBook Displaying a Calendar 195 byte actualChunk new Byte retCount - 1 Buffer.BlockCopy chunk 0 actualChunk 0 int retCount - 1 context.Response.BinaryWrite actualChunk public bool IsReusable get return false 4 The HTTP Handler in Listing 4.6 uses a SqlDataReader to retrieve a file from the database. The SqlDataReader is retrieved with a CommandBehavior.SequentialAccess parameter that enables the SqlDataReader to load data as a stream. The contents of the database column are pulled into memory in 8 040-byte chunks. The chunks are written to the browser with the Response.BinaryWrite method. Response buffering is disabled for the handler. The Response.Buffer property is set to the value False. Because buffering is disabled the output of the handler is not buffered in server memory before being transmitted to the browser. WARNING The method of working with large files described in this section only works with SQL

TÀI LIỆU LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.