private
DataRow
GetRow()
{
SqlDataAdapter
DataAdapter
=
new
SqlDataAdapter("select
*
from
ImageTable",
Connection);
DataSet
dataset
=
new
DataSet();
DataAdapter.Fill(dataset,
"ImageObject");
DataTable
table
=
dataset.Tables["ImageObject"];
if
(TextID.Text
==
"")
return
table.Rows[0];
else
{
int
Index
=
int.Parse(TextID.Text);
if
(Index
>=
0)
return
table.Rows[Index];
else
return
table.Rows[0];
}
}
private
byte[]
GetObject()
{
return
(byte[])GetRow()["ImageObject"];
}
private
String
GetObjectBinaryFile()
{
DataRow
Row
=
GetRow();
byte[]
Data
=
(byte[])Row["ImageObject"];
string
FileName
=
Path.GetFullPath(Server.MapPath(""))
+
"\\Bin\\"
+
(string)Row["Description"];
if
(!File.Exists(FileName))
{
FileStream
stream
=
new
FileStream(FileName,
FileMode.Create);
BinaryWriter
Writer
=
new
BinaryWriter(stream,
System.Text.Encoding.Default);
Writer.Write(Data);
stream.Close();
}
return
"./bin/"
+
(string)Row["Description"];
}
private
String
GetObjectText()
{
return
new
string(System.Text.Encoding.Default.GetChars(GetObject()))
;
}
private
void
Button2_Click(object
sender,
System.EventArgs
e)
{
//现在我就是,把它丢到./bin/目录,给bin读取权限。呵呵,以后再给,程序是写着玩的
Response.Redirect(GetObjectBinaryFile());
//TextBox2.Text
=
GetObjectText();
//Response.Clear();
//DataRow
Row
=
GetRow();
//this.Server.Transfer("");
//Response.Redirect("_blank");
//Response.WriteFile();
//Response.ContentType
=
Row["ImageObject"].ToString();
//Response.Write((byte[])Row["ImageObject"]);
}