1
我想將圖像存儲在一個文件夾中。爲此,我給文件夾路徑爲「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;
}
}
當給出路徑爲「.. \項目\網站\圖像文件中\」,我得到異常「訪問被拒絕的路徑.. \項目\網站\圖像文件中\「創建目錄時。
我該如何實現它?
兩種可能性:開始與更多的訪問權限的應用程序(例如,作爲管理員)或設置訪問權限爲啓動應用程序 –
@羅馬諾Zumbé用戶的路徑,我無法理解你的答案。你能再說一次嗎? –
請檢查此鏈接[https://stackoverflow.com/questions/4877741/access-to-the-path-is-denied](https://stackoverflow.com/questions/4877741/access-to-the-path -is-denied) – user2156791