我想将图像存储在一个文件夹中。为此,我给文件夹的路径为" D:\ Project \ Site \ ImageFiles"。通过使用此路径,我成功地将图像存储在文件夹中。
现在我想通过路径为" .. \ Project \ Site \ ImageFiles"来存储图像。
以下是代码:
public static bool SaveOriginalImage(string imageName, Image image)
{
try
{
var imageLocation = "D:\Project\Site\ImageFiles\";
if (!Directory.Exists(imageLocation))
{
Directory.CreateDirectory(imageLocation);
}
imageLocation = imageLocation + imageName;
var bitMapImage = new Bitmap(image.Width, image.Height);
bitMapImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);
using (var graphicImageContent = Graphics.FromImage(bitMapImage))
{
graphicImageContent.CompositingQuality = CompositingQuality.HighQuality;
graphicImageContent.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphicImageContent.SmoothingMode = SmoothingMode.HighQuality;
graphicImageContent.DrawImage(image, 0, 0, image.Width, image.Height);
}
bitMapImage.Save(imageLocation);
bitMapImage.Dispose();
return true;
}
catch (Exception ex)
{
return false;
}
}
当路径为" .. \ Project \ Site \ ImageFiles \"时,我得到异常"路径拒绝访问.. \ Project \ Site \ ImageFiles \&#34 ;在创建目录时。
我怎样才能实现它?
答案 0 :(得分:0)
var fullPath = Path.GetFullPath("..\Project\Site\ImageFiles")
https://msdn.microsoft.com/de-de/library/system.io.path(v=vs.110).aspx