У меня есть код для чтения данных (просмотра) с помощью OpenFileDialog, который я буду
читать это изображение, и я войду в базу данных, поэтому я делаю
преобразовать в байтовый тип данных, но когда я не просматриваю и сразу нажимаю кнопку сохранения,
появится сообщение об ошибке, любой может помочь мне решить эту проблему ..
как эта ошибка может быть заменена на окно сообщения ..
byte[] ReadFile(string sPath)
{
//Initialize byte array with a null value initially.
byte[] data = null;
//Use FileInfo object to get file size.
FileInfo fInfo = new FileInfo(sPath);
long numBytes = fInfo.Length;
//Open FileStream to read file
FileStream fStream = new FileStream(sPath, FileMode.Open, FileAccess.Read);
//Use BinaryReader to read file stream into byte array.
BinaryReader br = new BinaryReader(fStream);
//When you use BinaryReader, you need to supply number of bytes to read from file.
//In this case we want to read entire file. So supplying total number of bytes.
data = br.ReadBytes((int)numBytes);
return data;
}
private void btnImage_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "JPG files (*.jpg)|*.jpg";
DialogResult dlgRes = dlg.ShowDialog();
if (dlgRes != DialogResult.Cancel)
{
pctImage.ImageLocation = dlg.FileName;
txtImage.Text = dlg.FileName;
}
}