如果仅仅是上传一个文件,最好是使用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