奇码科技论坛 » 〖ASP〗 » [ASP技术文章]随机生成文件名的函数 转到动态网页
--> 本页主题: [ASP技术文章]随机生成文件名的函数 加为IE收藏 | 收藏主题 | 上一主题 | 下一主题
惢惢


级别: 管理员
精华: 3
发帖: 3831
经验: 29967 点
金钱: 17459 G币
贡献值: 0 点
好评度: 3 点
在线时间:0(小时)
注册时间:2006-07-21


[ASP技术文章]随机生成文件名的函数


文件1:showimage.aspx.cs


namespace ImageResizing {

public class MainDisplay : System.Web.UI.Page {

public void Page_Load(System.Object sender, System.EventArgs e) {

try {

System.Int32 _ImgID = System.Convert.ToInt32(Request.QueryString["ImgID"]);

System.Int32 _height = System.Convert.ToInt32(Request.QueryString["height"]);

System.Int32 _width = System.Convert.ToInt32(Request.QueryString["width"]);

System.Data.SqlClient.SqlConnection Con = new System.Data.SqlClient.SqlConnection( "server=localhost;database=northwind;trusted_connection=true" );

System.String SqlCmd = "SELECT * FROM Images WHERE ImageID = @ImageID";

System.Data.SqlClient.SqlCommand SqlCmdObj = new System.Data.SqlClient.SqlCommand( SqlCmd, Con );

SqlCmdObj.Parameters.Add("@ImageID", System.Data.SqlDbType.Int).Value = _ImgID;

Con.Open();

System.Data.SqlClient.SqlDataReader SqlReader = SqlCmdObj.ExecuteReader();

SqlReader.Read();

System.Web.HttpContext.Current.Response.ContentType = "image/pjpeg";

System.Drawing.Image _image = System.Drawing.Image.FromStream( new System.IO.MemoryStream( (byte[])SqlReader["Image"] ) );

System.Drawing.Image _newimage = _image.GetThumbnailImage( _width, _height, null, new System.IntPtr());

_newimage.Save( System.Web.HttpContext.Current.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg );

} catch (System.Exception Ex) {

System.Web.HttpContext.Current.Trace.Write(Ex.Message.ToString());

}

}

}

}


文件2:显示图片之用,把querystring传入
<html>
<body>

<img src="showimage.aspx?ImgID=202&height=150&width=150">
</body>
</html>



顶端 Posted:2006-10-26 01:21 | [楼 主]

 奇码科技论坛 -> 〖ASP〗
快速发帖 顶端
内容
HTML 代码不可用

使用签名
Wind Code自动转换

字数检查 恢复数据
 认证码:  
按 Ctrl+Enter 直接提交
表情 [更多]

Powered by PHPWind v5.3 Code © 2003-07 PHPWind