1. 直接 用上传到数据库里
//得到提交的文件
Stream fileDataStream = MyFile.PostedFile.InputStream; //得到文件大小
int fileLength = MyFile.PostedFile.ContentLength; //创建数组
byte[] fileData = new byte[fileLength]; //把文件流填充到数组
fileDataStream.Read(fileData,0,fileLength); //得到文件名字
string fileName=MyFile.PostedFile.FileName;
string fileTitle = fileName.Substring(fileName.LastIndexOf("\\") + 1); //得到文件类型
string fileType = MyFile.PostedFile.ContentType; //构建数据库连接,SQL语句,创建参数
SqlConnection connection = new SqlConnection("Server=localhost;uid=sa;pwd=chen;Database=aspnetpager");
SqlCommand command = new SqlCommand ("INSERT INTO TestFiles (MyFileName,MyFile,FileType)" + 
"VALUES (@MyFileName,@MyFile,@FileType)", connection); SqlParameter paramTitle = new SqlParameter ("@MyFileName", SqlDbType.VarChar,35); 
paramTitle.Value = fileTitle;
command.Parameters.Add(paramTitle); SqlParameter paramData = new SqlParameter ("@MyFile", SqlDbType.Image);
paramData.Value = fileData;
command.Parameters.Add(paramData); SqlParameter paramType = new SqlParameter ("@FileType", SqlDbType.VarChar,25); 
paramType.Value = fileType;
command.Parameters.Add(paramType); //打开连接,执行查询
connection.Open();
command.ExecuteNonQuery();
connection.Close(); Message.Text="你的文件已经成功上载";

解决方案 »

  1.   

    下载代码
    // 在此处放置用户代码以初始化页面
    string sql="SELECT * FROM TestFiles WHERE ID = '" + Request.QueryString["ID"] + "'";
    SqlConnection connection = new SqlConnection("Server=localhost;uid=sa;pwd=chen;Database=aspnetpager");
    SqlCommand command = new SqlCommand(sql, connection);
    connection.Open();
    SqlDataReader dr = command.ExecuteReader();
    if(dr.Read())
    {
    Response.Clear();
    Response.AddHeader("Content-Type","application/OCTET-STREAM;");
    Page.Response.AddHeader("Content-Disposition","attachment;filename=" + System.Web.HttpUtility.UrlEncode(dr["MyFileName"].ToString(),System.Text.Encoding.UTF8));
                    Page.Response.AddHeader("Content-Length",((byte[])dr["MyFile"]).Length.ToString());
    Response.ContentEncoding = System.Text.Encoding.UTF8;
              //    Response.ContentType =dr["FileType"].ToString(); //可以在IE中显示图片和word文档  //不加这句为直接输出下载
    Response.BinaryWrite((byte[])dr["MyFile"]);
    Response.End();
    }
    dr.Close();

    connection.Close();
      

  2.   

    注 : 用的SQLServer不是oracle