|
|
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<%@ Import Namespace="System.IO" %>
<script language="C#" runat="server">
void Page_load(object Sender, EventArgs E) {
MemoryStream stream = new MemoryStream();
SqlConnection connection;
connection = new SqlConnection("server=localhost;database=pubs;uid=sa;pwd=");
try {
connection.Open();
SqlCommand command;
command = new SqlCommand("select logo from pub_info where pub_id=\’0736\’", connection);
byte[] image;
image = command.ExecuteScalar();
stream.Write(image, 0, image.Length);
bitmap imgbitmap;
imgbitmap = new Bitmap(stream);
Response.ContentType = "image/gif";
imgbitmap.Save(Response.OutputStream, ImageFormat.Gif);
}
finally {
connection.Close();
stream.Clse();
}
}
</script>
MemoryStream stream = new MemoryStream(); string constr = System.Configuration.ConfigurationSettings.AppSettings["SQLConnectionString"];string slct="select imageSrc from dbo.image_excise where id=1";SqlConnection scon = new SqlConnection(constr);//string slct = "select ThemeFileData from SPS_M_ThemeFile where ThemeFileCD=" + imgid;SqlCommand scmd = new SqlCommand(slct,scon);scon.Open();SqlDataReader sdr = scmd.ExecuteReader();Response.ContentType = "image/jpeg";if(sdr.Read()){if(((byte[])sdr.GetValue(0)).Length != 0){Response.BinaryWrite((byte[])sdr.GetValue(0));return;}}try{FileStream fs = new FileStream(Server.MapPath("Images/Image_NoPicture.gif"),FileMode.Open,FileAccess.Read);byte[] mydata = new byte[fs.Length];int Length = Convert.ToInt32(fs.Length);fs.Read(mydata,0,Length);fs.Close();this.Response.OutputStream.Write(mydata,0,Length);}catch(Exception ex){return;}sdr.Close();scon.Close();this.Response.End();
写
HtmlInputFile[] tempfile = new HtmlInputFile[3];tempfile[0] =this.imageFile1;tempfile[1] =this.imageFile2;tempfile[2] =this.imageFile3;//16011for(int i=0;i<3;i++){byte[] buff = new byte[tempfile.PostedFile.ContentLength];tempfile.PostedFile.InputStream.Read(buff,0,tempfile.PostedFile.ContentLength);try{System.Drawing.Image img = System.Drawing.Image.FromStream(new System.IO.MemoryStream(buff));}catch{return ;}SqlParameter[] spr = new SqlParameter[2];spr[0]=new SqlParameter("@imageTitle",SqlDbType.NVarChar);spr[0].Value="test"+i.ToString();spr[1] = new SqlParameter("@imageSrc",SqlDbType.Image);spr[1].Value = buff;SqlHelper.ExecuteNonQuery(SqlHelper.dsn,CommandType.StoredProcedure,"imageInsert",spr);} |
|