我想保存我上传的图像在项目文件夹中。但它被保存在库存\bin\调试\资产bin文件夹中我的项目。
将图像保存在文件夹中的目的,因为我只想将图像名称保存到数据库,当我需要显示图像时,我可以从/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
保存在我的数据库中。
1条答案
按热度按时间4nkexdtk1#
私有void btnUploadLogo_Click(对象发送方,路由的事件参数e){打开文件对话框op =新的打开文件对话框();