venky n

venky n

  • NA
  • 110
  • 38.1k

how to image retireve for single image location

Mar 7 2015 2:28 AM
image store successfully,but not retrieve for particular  image location





namespace DisplayingImages
{
    public partial class Default : System.Web.UI.Page
    {
        public string query, constr;
        public SqlConnection con;
        public void connection()
        {
            constr = ConfigurationManager.ConnectionStrings["Imagecon"].ToString();
            con = new SqlConnection(constr);
            con.Open();


        }

        protected void Page_Load(object sender, EventArgs e)
        {
            Label1.Visible = false;
            if (!IsPostBack)
            {

            }
        }


        protected void upload(object sender, EventArgs e)
        {
            Imageupload();
        }


        private void Imageupload()
        {
            if (FileUpload1.HasFile)
            {
                int imagefilelenth = FileUpload1.PostedFile.ContentLength;
                byte[] imgarray = new byte[imagefilelenth];
                HttpPostedFile image = FileUpload1.PostedFile;
                image.InputStream.Read(imgarray, 0, imagefilelenth);
                connection();
                query = "Insert into  TBLImage1 (room) values (@room)";
                SqlCommand com = new SqlCommand(query, con);
                com.Parameters.AddWithValue("@room", SqlDbType.Image).Value = imgarray;
                com.ExecuteNonQuery();
                Label1.Visible = true;
                Label1.Text = "Image Is Uploaded successfully";

              }

        }

        protected void imageRetrieve_Click(object sender, EventArgs e)
        {
            using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Imagecon"].ConnectionString))
            {
                con.Open();
               SqlCommand com= new SqlCommand("select room form TBLImage1 where trnid=@id", con);
                   if (con.State == ConnectionState.Closed)
                    {
                        con.Open();
                    }
                    SqlDataReader dr = com.ExecuteReader();
                    if (dr.HasRows && dr.Read())
                    {
                      retrive.ImageUrl = "Handler3.ashx?trnid=" + retrive;
                    }
                    else
                    {
                        Response.Write("Record With This ID Note Found");
                    }

                }

            }
namespace DisplayingImages
{
    /// <summary>
    /// Summary description for Handler1
    /// this application is created by vithal wadje for C# corner
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

    public class Handler1 : IHttpHandler
    {
        //createting the object of Default.aspx class page to
        //call connection and use strings variable
        Default cls = new Default();
      
        public void ProcessRequest(HttpContext context)
        {
            //storing the querystring value that comes from Defaul.aspx page

            string displayimgid=context.Request.QueryString["trnid"].ToString();
            cls.connection();
            //retriving the images on the basis of id of uploaded
            //images,by using the querysting valaues which comes from Defaut.aspx page
            cls.query="select room from TBLImage1 where TRNID="+displayimgid;
            SqlCommand com=new SqlCommand(cls.query,cls.con);
            SqlDataReader dr=com.ExecuteReader();
            dr.Read();
            context.Response.BinaryWrite((Byte[])dr[0]);
            context.Response.End();
          

        }



Answers (1)