當圖像文件未找到或不存在時,如何設置默認圖像? 我得到的錯誤是設置默認圖像路徑
因爲名字8813.jgp
文件不存在。我想將其設置爲1.jpg
。我如何檢查它是否存在。
IAM使用此代碼
public void profilepicture()
{
DataTable dtprofile = new DataTable();
DataSet dsprofile = new DataSet();
string path;
SqlCommand command = new SqlCommand();
SqlDataAdapter adapter = new SqlDataAdapter();
try
{
dsprofile.Clear();
dtprofile.Clear();
command.Connection = myConnection;
command.CommandText = "//some query//'";
myConnection.Open();
adapter.SelectCommand = command;
adapter.Fill(dtprofile);
adapter.Fill(dsprofile);
}
catch (Exception ex)
{
MessageBox.Show("error" + ex);
myConnection.Close();
}
path = dsprofile.Tables[0].Rows[0][0].ToString() + "\\" + number + ".jpg";
pictureEdit2.Image = Image.FromFile(path);
myConnection.Close();
}
https://msdn.microsoft.com/en-us/library/system.io.file .exists(v = vs.110).aspx – Bharadwaj