1private void Button1_Click(object sender, System.EventArgs e)//上传
2 {
3 int intDocLen = File1.PostedFile.ContentLength;
4 byte[] Docbuffer = new byte[intDocLen];
5 Stream objStream;
6 objStream = File1.PostedFile.InputStream;
7 objStream.Read(Docbuffer, 0, intDocLen);
8 OracleConnection con = new OracleConnection("user id=nj;data source=njoraclelocal;password=124578;");
9 con.Open();
10 OracleCommand cmd = new OracleCommand("InSert Into AAAA(WORD) Values(:word)",con);
11 OracleParameter para = new OracleParameter(":word",OracleType.Blob);
12 para.Value = Docbuffer;
13 para.Size = Docbuffer.Length;
14 cmd.Parameters.Add(para);
15 cmd.ExecuteNonQuery();
16 con.Close();
17// objStream.Close();
18 }
19
20 private void Button2_Click(object sender, System.EventArgs e)//下载
21 {
22// OracleConnection con = new OracleConnection("user id=nj;data source=NJORACLELOCAL;password=124578;");
23// OracleCommand cmd = new OracleCommand("Select * From AAAA",con);
24// con.Open();
25// OracleDataReader dr = cmd.ExecuteReader();
26// dr.Read();
27// Byte[] words = (Byte[])dr["WORD"];
28// Response.OutputStream.Write(words,0,words.Length);
29
30
31 string queryString = "Select * From AAAA where ROWID = 'AAAHsVAAJAAAAuHAAB'";
32 OracleConnection conn = new OracleConnection("user id=nj;data source=NJORACLELOCAL;password=124578;");
33 OracleCommand cmd = new OracleCommand(queryString,conn);
34 conn.Open();
35 OracleDataReader dr = cmd.ExecuteReader();
36 if (dr.Read())
37 {
38 Response.Clear();
39 Response.AddHeader("Content-Type", "application/msword");
40// Response.AddHeader("content-type","text/html");
41 Response.BinaryWrite((byte[])dr["WORD"]);//WDSJ为该BLOB字段名
42 }
43 dr.Close();
44 conn.Close();
45
46 }
47
48
2 {
3 int intDocLen = File1.PostedFile.ContentLength;
4 byte[] Docbuffer = new byte[intDocLen];
5 Stream objStream;
6 objStream = File1.PostedFile.InputStream;
7 objStream.Read(Docbuffer, 0, intDocLen);
8 OracleConnection con = new OracleConnection("user id=nj;data source=njoraclelocal;password=124578;");
9 con.Open();
10 OracleCommand cmd = new OracleCommand("InSert Into AAAA(WORD) Values(:word)",con);
11 OracleParameter para = new OracleParameter(":word",OracleType.Blob);
12 para.Value = Docbuffer;
13 para.Size = Docbuffer.Length;
14 cmd.Parameters.Add(para);
15 cmd.ExecuteNonQuery();
16 con.Close();
17// objStream.Close();
18 }
19
20 private void Button2_Click(object sender, System.EventArgs e)//下载
21 {
22// OracleConnection con = new OracleConnection("user id=nj;data source=NJORACLELOCAL;password=124578;");
23// OracleCommand cmd = new OracleCommand("Select * From AAAA",con);
24// con.Open();
25// OracleDataReader dr = cmd.ExecuteReader();
26// dr.Read();
27// Byte[] words = (Byte[])dr["WORD"];
28// Response.OutputStream.Write(words,0,words.Length);
29
30
31 string queryString = "Select * From AAAA where ROWID = 'AAAHsVAAJAAAAuHAAB'";
32 OracleConnection conn = new OracleConnection("user id=nj;data source=NJORACLELOCAL;password=124578;");
33 OracleCommand cmd = new OracleCommand(queryString,conn);
34 conn.Open();
35 OracleDataReader dr = cmd.ExecuteReader();
36 if (dr.Read())
37 {
38 Response.Clear();
39 Response.AddHeader("Content-Type", "application/msword");
40// Response.AddHeader("content-type","text/html");
41 Response.BinaryWrite((byte[])dr["WORD"]);//WDSJ为该BLOB字段名
42 }
43 dr.Close();
44 conn.Close();
45
46 }
47
48
PS:给下载文件指定默认名
Response.AddHeader("Content-Type", StrDownType(fileExten));
Response.AddHeader("Content-Disposition", "attachment;filename="+HttpUtility.UrlEncode("自定义文件名", System.Text.Encoding.UTF8)+"."+fileExten);
/// <summary>
/// 根据后缀确定流类型
/// </summary>
/// <param name="extension">后缀名</param>
/// <returns></returns>
private static string StrDownType(string extension)
{
if (extension == "doc" || extension == "docx")
{
return "application/msword";
}
else if (extension == "xls" || extension == "xlsx")
{
return "application/vnd.ms-excel";
}
return "text/html";
}