helia64
پنج شنبه 12 مرداد 1391, 13:26 عصر
سلام دوستان
من با مشکل عجیبی بر خوردم درمورد اوردن عکس به درون gridview در صفحه وبم
من در برنامه ام عکسی که از کاربر گرفتم و در جدول ذخیره شده را میتونم بیارم در gw
اما عکسی که با اسکنر ذخیره کردم و در بانک هم ذخیره شده وفرمتش هم همون jpg گذاشتم که بتونم از همون فایل handler ی که برای تبدیل عکس های کاربران داشتم استفاده کنم. توی خط زیر خطا می گیره
این کدهای handler هست
public
classShowimg : IHttpHandler {
publicvoid ProcessRequest (HttpContext context) {
Int32 id;
if (context.Request.QueryString["id"] != null)
id = Convert.ToInt32(context.Request.QueryString["id"]);
else
thrownewArgumentException("No parameter specified");
context.Response.ContentType = "image/jpeg";
Stream strm = ShowEmpImage(id);
byte[] buffer = newbyte[4096];
int byteSeq = strm.Read(buffer, 0, 4096);
while (byteSeq > 0)
{
context.Response.OutputStream.Write(buffer, 0, byteSeq);
byteSeq = strm.Read(buffer, 0, 4096);
}
//context.Response.BinaryWrite(buffer);
}
publicStream ShowEmpImage(int id)
{
SqlConnection connection = newSqlConnection("Data Source=.;Initial Catalog=NezamPezeshki;Integrated Security=True");
// string conn = ConfigurationManager.ConnectionStrings["EmployeeConnString"].ConnectionString;
//SqlConnection connection = new SqlConnection(conn);
string sql = "SELECT pic FROM DrInfo WHERE FileRow= @id";
SqlCommand cmd = newSqlCommand(sql, connection);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@id",id);
connection.Open();
object img = cmd.ExecuteScalar();
try
{
returnnewMemoryStream((byte[])img);
}
catch
{
returnnull;
}
finally
{
connection.Close();
}
}
حالا خطا رو از این خط می گیره
byteSeq = strm.Read(buffer, 0, 4096);
ودیگه اجازه نمایش عکسی که اسکن شده را نمیده حجم عکس هم حدود 8 کیلو بایت هست
لطفا راهنماییم کنید
ممنون
من با مشکل عجیبی بر خوردم درمورد اوردن عکس به درون gridview در صفحه وبم
من در برنامه ام عکسی که از کاربر گرفتم و در جدول ذخیره شده را میتونم بیارم در gw
اما عکسی که با اسکنر ذخیره کردم و در بانک هم ذخیره شده وفرمتش هم همون jpg گذاشتم که بتونم از همون فایل handler ی که برای تبدیل عکس های کاربران داشتم استفاده کنم. توی خط زیر خطا می گیره
این کدهای handler هست
public
classShowimg : IHttpHandler {
publicvoid ProcessRequest (HttpContext context) {
Int32 id;
if (context.Request.QueryString["id"] != null)
id = Convert.ToInt32(context.Request.QueryString["id"]);
else
thrownewArgumentException("No parameter specified");
context.Response.ContentType = "image/jpeg";
Stream strm = ShowEmpImage(id);
byte[] buffer = newbyte[4096];
int byteSeq = strm.Read(buffer, 0, 4096);
while (byteSeq > 0)
{
context.Response.OutputStream.Write(buffer, 0, byteSeq);
byteSeq = strm.Read(buffer, 0, 4096);
}
//context.Response.BinaryWrite(buffer);
}
publicStream ShowEmpImage(int id)
{
SqlConnection connection = newSqlConnection("Data Source=.;Initial Catalog=NezamPezeshki;Integrated Security=True");
// string conn = ConfigurationManager.ConnectionStrings["EmployeeConnString"].ConnectionString;
//SqlConnection connection = new SqlConnection(conn);
string sql = "SELECT pic FROM DrInfo WHERE FileRow= @id";
SqlCommand cmd = newSqlCommand(sql, connection);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@id",id);
connection.Open();
object img = cmd.ExecuteScalar();
try
{
returnnewMemoryStream((byte[])img);
}
catch
{
returnnull;
}
finally
{
connection.Close();
}
}
حالا خطا رو از این خط می گیره
byteSeq = strm.Read(buffer, 0, 4096);
ودیگه اجازه نمایش عکسی که اسکن شده را نمیده حجم عکس هم حدود 8 کیلو بایت هست
لطفا راهنماییم کنید
ممنون