Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Post
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
4
Reply
Image Not show on Cloud Page But shows on my Machine
Abraham Olatubosun
May 10 2017 1:41 AM
236
Reply
Dear Code Masters,
Good day to you all, I have a web page that have a textbox and a button for searching student record.
if the student id is entered in the textbox and the button is clicked the c# code behind search and displayed the record if found. The database structure is shown below :
once we search the record "cis/001" i expect the name, RegNo and the image to displayed on my development machine it worked fine, but after deploying both the database and the files to the cloud it is not working.
i have tried using this code:
Image1.ImageUrl =
"ImageHandler.ashx?id="
+ "CIS/001"
DT = ConnectAll.GetTableID(id);
foreach
(DataRow r
in
DT.Rows)
{
Byte[] bytes = (Byte[])r[
"picture"
];
string
Base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
Image1.ImageUrl =
"data:image/png;base64,"
+ Base64String;
}
;
the imageHandler page is a GenericHandler which have the following code:
public
void
ProcessRequest (HttpContext context) {
//context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
try
{
string
id = context.Request.QueryString[
"id"
].ToString();
using
(SqlConnection cn =
new
SqlConnection(ConnectAll.ConnectMe()))
{
cn.Open();
string
SQL =
"Select * from tbl_studReg where id ="
+id;
SqlCommand cmd =
new
SqlCommand(SQL, cn);
//cmd.CommandType = CommandType.Text;
//cmd.Parameters.AddWithValue("@id", id.ToString());
SqlDataReader r = cmd.ExecuteReader();
while
(r.Read())
{
context.Response.BinaryWrite((
byte
[])r[
"picture"
]);
}
}
}
catch
(Exception ex)
{
}
}
these didn't work, i also tried the following code too
DT = ConnectAll.GetTableID(id);
foreach
(DataRow r
in
DT.Rows)
{
Byte[] bytes = (Byte[])r[
"picture"
];
string
Base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
Image1.ImageUrl =
"data:image/png;base64,"
+ Base64String;
}
above i have a class that return a datatable (DT)
all these did wor either but on my machine both method work fine displaying the image and the other records. Please can anyone help me?
thank you all
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
4
)
Next Recommended Forum
return value to the main fuction
how clear dropdwonlist if searh is null and how to get again