Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi,
 
I have to upload images into my windows application using openDialogBox. Is there any method to store the images inside the application.? How is this possible? Please give me any idea about this.
Posted 31-Jul-12 16:25pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

What do you mean by 'upload' ? You can store images anywhere you like, so long as you have permission. I'd think a folder inside the app data area of windows is a logical place, much easier than storing it in a DB.
  Permalink  
Comments
Neha Thanka at 31-Jul-12 21:30pm
   
I want to store photos ofb employees. These photos are selecting through openFileDialog box. Then how can that image stored in a folder?
Christian Graus at 31-Jul-12 21:33pm
   
Use Environment.SpecialFolder to find the location, System.IO.Path to build your new file location string, and System.IO.File to copy the file.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

1. use openfiledialog to ask the file from the user.
2. filter the openfiledialog to accept images only.
3. Use File.Copy function to copy file from openfiledialog opened filepath to your chosen destination path.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

I think the better option to storing image is to convert image to byte[] then store it in Database
Open a File First
byte[] big;
private void button7_Click(object sender, EventArgs e)
        {
             OpenFD.Title = "Select Files";
            OpenFD.Filter = "Jpg|*.jpg|Jpge|*.jpge|Gif|*.gif";
            OpenFD.FileName = null;
            string fileName;
            if (OpenFD.ShowDialog() != DialogResult.Cancel)
            {
                querybuilder qu = new querybuilder();
                fileName = OpenFD.FileName;
                Object refmissing = System.Reflection.Missing.Value;
                try
                {
                     // show it to picturebox
                    pictureBox2.Load(fileName);
                     // Here get_image is a function and Big is the byte[] type
                    big = get_image(fileName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error" + ex.Message.ToString());
                }
            }
        }
get_image function is below
public byte[] get_image(string filePath)
        {
            FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
            BinaryReader reader = new BinaryReader(stream);
            byte[] photo = reader.ReadBytes((int)stream.Length);
            reader.Close();
            stream.Close();
 
            return photo;
        }
And now make sql query
string sqlquery="insert into Tablename(id,image) values(1,@big)";
SqlParameter param = new SqlParameter("@big", SqlDbType.Binary);
    param.Value = big;
Note:- Create Sqlcommand self I didn't include it in that solution
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

private void cmdBrowser_Click(object sender, EventArgs e)
        {
            OpenFileDialog fileOpen = new OpenFileDialog();
            fileOpen.Title = "Open Image file";
            fileOpen.Filter = "JPG Files (*.jpg)| *.jpg";
 
            if (fileOpen.ShowDialog() == DialogResult.OK)
            {
                picImage.Image = Image.FromFile(fileOpen.FileName);
            }
            fileOpen.Dispose();
        }
 

 
make on button click on windows application.
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 7,065
1 DamithSL 4,989
2 Maciej Los 4,866
3 Sergey Alexandrovich Kryukov 4,547
4 Kornfeld Eliyahu Peter 4,314


Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 7 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100