如果僅僅是上傳一個文件,最好是使用FileUpload控件, 可以使用FileUpload1.FileContent.Length得到文件大小, FileUpload1.FileBytes得到其字節數組, 代碼略.
如果要上傳多個文件, 其客戶端代碼與使用ASP.NET上傳多個文件到服務器基本相同, 本例中加入了下載的示例代碼。
效果圖如下:
數據庫腳本
create database FileDB go use FileDB go create table dbo.Files ( id int identity primary key ,FileName varchar(50) not null ,FileSize int not null ,FileData image not null --,UpTime DateTime default getdate() --,DownLoadTimes int default 0 ) go
頁面代碼:MutlileFileUploadToDB.aspx
後臺代碼:MutlileFileUploadToDB.aspx.cs