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
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.