Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;


namespace MOSS
{
    public partial class StoreImageInDB : System.Web.UI.Page
    {

        protected System.Web.UI.HtmlControls.HtmlInputFile Upload;
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Page_Init(object sender, EventArgs e)
        {

            try
            {
                if (Request.QueryString["id"] == null)
                {
                    string id = "B0001";
                    Response.Clear();
                    Response.ContentType = "image/jpeg";
                    System.Drawing.Image image = RetrieveImage(id);
                    Bitmap bmPhoto = new Bitmap(image);
                    bmPhoto.SetResolution(72, 72);
                    bmPhoto.Save("lkfjlk.jpeg",System.Drawing.Imaging.ImageFormat.Jpeg);
                    bmPhoto.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);

                    //System.IO.File.Copy(
                    bmPhoto.Dispose();
                }
            }
            catch (Exception ee)
            {

            }

        }

        private System.Drawing.Image RetrieveImage(string id)
        {
            System.Drawing.Image image = null;
            //command.CommandText = "SELECT Photo FROM Photos  WHERE PhotoId = @PhotoId";
            //command.Parameters.AddWithValue("@PhotoId", photoId);
            byte[] imageData = DAlAutoComplete.GetImgDB(id);//(byte[])command.ExecuteScalar();
            MemoryStream memStream = new MemoryStream(imageData);
            image = System.Drawing.Image.FromStream(memStream);
            return image;
        }

    

        protected void OnUpload(object sender, EventArgs e)
        {
          
            if (FileUpload1.HasFile)
            {
                using (BinaryReader reader = new BinaryReader(FileUpload1.PostedFile.InputStream))
                {
                    byte[] image = reader.ReadBytes(FileUpload1.PostedFile.ContentLength);
                    int i = DAlAutoComplete.ImageInsetDB(image);
                }

            }





        }
    }
}


I am converting binary data into bitmap image but I need to save into a folder and rename the image.
Posted
Updated 2-Feb-11 0:33am
v2
Comments
Umair Feroze 2-Feb-11 7:12am    
Did not get your point. You are already saving the image into folder using the following line:
bmPhoto.Save("lkfjlk.jpeg",System.Drawing.Imaging.ImageFormat.Jpeg);
Please elaborate your question
karthikkushala 3-Feb-11 0:21am    
i wrote but it not saving into seporate folder which and how to give name dynamically

1 solution

Please check the following link:Link[^]
 
Share this answer
 
v2
Comments
Sandeep Mewara 2-Feb-11 13:21pm    
Don't wrap your answers in PRE tag. PRE tags are for wrapping code part.

Earlier, I thought you did it by mistake but I saw that here again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900