Hi,
I have made a simple Work out for you.
Place a Button and Pictuerbox on you winform.button1,pictureBox1
In Button click open the jpg file and load it in pictuer box. I have used try catch if the selected file is valid jpeg then display in pictuer box .if other file like texct or exe file extention change as jpg and upload display the error message from exceptaiton part.
see the buttonclikc code here for details.
private void button1_Click(object sender, EventArgs e)
{
string filename = "";
OpenFileDialog open = new OpenFileDialog() { Filter = "Image Files|*.JPG;*.JPEG;" };
if (open.ShowDialog() == DialogResult.OK)
{
filename = open.FileName;
}
if (filename != "")
{
string image = filename;
try
{
Bitmap bmp = new Bitmap(image);
pictureBox1.Image = bmp;
FileStream fs = new FileStream(image, FileMode.Open, FileAccess.Read);
byte[] bimage = new byte[fs.Length];
fs.Read(bimage, 0, Convert.ToInt32(fs.Length));
fs.Close();
byte[] Photo = bimage;
}
catch (Exception ex)
{
MessageBox.Show("Select the valid file");
}
}
}