I am trying to create a project in c# , I want to upload images in to database if its size is <150 kb . How to set the limitation for uploading images? I don't know how to expand it ? please help thanks in advance
private void Browsebutton3_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "images only.|*.jpg; *.jpeg; *.png";
DialogResult dr = ofd.ShowDialog();
pictureBox1.Image = Image.FromFile(ofd.FileName);
//pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
textBox5.Text = ofd.FileName;
}
Use the FileInfo class to get the file size. The number of bytes are accessible by FileInfo.Length
if (new FileInfo(ofd.FileName).Length > (150 * 1024))
{
throw new ApplicationException(); //handle invalid file size here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With