無效字符將圖片數據庫中的後,我想將圖片複製和重命名到另一個文件夾,但我總是得到這個錯誤 - 儘管路徑是正確的路徑無效字符。我已經從我的目錄複製並粘貼路徑以避免錯誤。最初,這段代碼屬於我的程序的添加圖像部分(它正在工作)。但是,當我試圖複製粘貼這段代碼來更新圖像部分它不再工作,我真的不知道爲什麼。複製文件 - 系統參數異常,在路徑
//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:\用戶\用戶\文檔\ Visual Studio的2013 \項目\ ID \ ID \ BIN \調試\ formattedpic \ 0000002-JOHN-ACCESS-IDPIC.jpg – George
這看起來OK。那麼pathID.Text呢? – Bedford