0
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;
}
}
여러 줄에 걸쳐있는 코드를 입력 할 때 백틱을 사용하지 마십시오. 각 줄을 네 칸 씩 들여 쓰기해야합니다. – Amy
어떤 오류가 발생합니까? – Fischermaen
바이트 배열로만 읽는 경우에는'BinaryReader'가 필요하지 않습니다. [[FileStream.Read (byte [] array, int start, int count)']를 사용할 수 있습니다.] (http://msdn.microsoft.com/en-us/library/system.io.filestream.read.aspx) 방법. – Amy