I hope this helps
using (OpenFileDialog dlg = new OpenFileDialog())
{
dlg.Filter = "JPG Files (*.jpg)|*.jpg|JPEG Files (*.jpeg)|*.jpeg|bmp Files (*.bmp)|*.bmp|PNG Files (*.png)|*.png|GIF Files (*.gif)|*.gif";
if (dlg.ShowDialog() == DialogResult.OK)
{
FileInfo file = new FileInfo(dlg.FileName);
if (file.Length == 0)
{
MessageBox.Show("Invalid image. Please select valid image.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else if (file.Length > 2097152)
{
MessageBox.Show("Image size cannot exceed 2MB.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}
}