我想将上传的图像保存在项目文件夹中。但它保存在我项目的 Inventory \ bin \ Debug \ assets bin文件夹中。
将图像保存到文件夹中的目的,因为我只想将图像名称保存到db,当我需要显示图像时,我可以从/assets/xyz.png
这是我保存图片的代码,
private void btnUploadLogo_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog op = new OpenFileDialog();
op.Title = "Select a picture";
op.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" +
"JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
"Portable Network Graphic (*.png)|*.png";
if (op.ShowDialog() == true)
{
string appPath = Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory) + @"\assets\";
var fileNameToSave = DateTime.Now.ToFileNameFormat() + Path.GetExtension(op.SafeFileName);
var imagePath = Path.Combine(appPath + fileNameToSave);
if (!Directory.Exists(appPath))
{
Directory.CreateDirectory(appPath);
}
File.Copy(op.FileName, imagePath);
imgUpload.Source = new BitmapImage(new Uri(imagePath));
panelImg.Visibility = Visibility.Visible;
}
}
因为我想在我的数据库中保存assets/xyz.png
。