그림을 데이터베이스에 저장 한 후 그림을 다른 폴더로 복사하고 이름을 바꾸고 싶지만 항상이 오류가 발생합니다. 경로가 올바르지 만 경로의 문자가 잘못되었습니다. . 오류를 피하기 위해 이미 내 디렉토리에서 경로를 복사하여 붙여 넣습니다. 처음에,이 코드는 내 프로그램의 이미지 추가 부분에 속합니다 (그리고 작동 중입니다). 그러나 이미지 부분을 업데이트하기 위해이 코드를 복사 해 붙여 넣으려고하면 더 이상 작동하지 않습니다. 이유를 모르겠습니다.파일 복사 - 시스템 인수 예외, 경로의 문자가 잘못되었습니다.
//choosing a picture and putting the path to pathID.Text
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "All Files(*.*)|*.*|JPG Files(*.jpg)|.jpg|PNG Files(*.png)|*.png";
dlg.Title = "Select Employee Picture.";
if (dlg.ShowDialog() == DialogResult.OK)
{
string picLoc = dlg.FileName.ToString();
pathID.Text = picLoc;
pictureBox5.ImageLocation = picLoc;
this.pictureBox5.SizeMode = PictureBoxSizeMode.StretchImage;
}
if (pathID.Text == "")
{
MessageBox.Show("You didn't add your ID Picture");
}
else
{
try
{
//converting image to binary
byte[] imageID = null;
FileStream fstream = new FileStream(this.pathID.Text, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fstream);
imageID = br.ReadBytes((int)fstream.Length);
fstream.Close();
//storing image to database
string login = "server=localhost;database=id;uid=root;password=root;";
MySqlConnection conn = new MySqlConnection(login);
conn.Open();
MySqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "UPDATE picture SET `Picture_Employee`[email protected] where [email protected]";
cmd.Parameters.AddWithValue("@EMP", imageID);
cmd.Parameters.AddWithValue("@ID", sampleID.Text);
cmd.ExecuteNonQuery();
conn.Close
//copying file from one path to another
string newp = "C:\\Users\\Owner\\Documents\\Visual Studio 2013\\Projects\\ID\\ID\\bin\\Debug\\formattedpic\\" + sampleID.Text + "-" + label1.Text + "-IDPIC.jpg";
if (File.Exists(newp))
{
int i = 1;
while (File.Exists(newp))
{
newp = "C:\\Users\\Owner\\Documents\\Visual Studio 2013\\Projects\\ID\\ID\\bin\\Debug\\formattedpic\\" + sampleID.Text + "-" + label1.Text + "-IDPIC"+i.ToString()+".jpg";
i++;
}
}
//tried to show path in message box - it is showing correctly
MessageBox.Show(newp);
System.IO.File.Copy(pathID.Text, newp);
MessageBox.Show("ID PICTURE Updated");
}
}
당신이 우리에게 경로에 대한 예를 보여 주시겠습니까? (newp) – Bedford
C : \ Users \ Owner \ Documents \ Visual Studio 2013 \ 프로젝트 \ ID \ ID \ bin \ Debug \ formattedpic \ 0000002-JOHN-ACCESS-IDPIC.jpg – George
괜찮아 보입니다. pathID.Text는 어때? – Bedford