1

I want to store the image in a folder. For that, i give path of folder as "D:\Project\Site\ImageFiles". By using this path, I stored the image in the folder successfully.

Now I want to store the image by giving path as "..\Project\Site\ImageFiles".

Here is the code:

 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;
        }
    }

When giving path as "..\Project\Site\ImageFiles\", i get exception "Access is denied for the path ..\Project\Site\ImageFiles\ " when creating directory.

How can I achieve it?

Nivitha G
  • 243
  • 3
  • 7
  • 17
  • Two possibilities: Start your application with more access right (e.g. as administrator) or set access permissions to the path for the user that starts the application – Romano Zumbé Jun 19 '17 at 09:28
  • @ Romano Zumbé, I cannot able to understand your answer. Can you tell once again. – Nivitha G Jun 19 '17 at 09:36
  • Please check this link [https://stackoverflow.com/questions/4877741/access-to-the-path-is-denied](https://stackoverflow.com/questions/4877741/access-to-the-path-is-denied) – A.M. Patel Jun 19 '17 at 09:38
  • I think the problem is, that you really don't have the right to access the folder. Start the application as administrator (right click "start as Administrator") then try again – Romano Zumbé Jun 19 '17 at 09:39

1 Answers1

0
var fullPath = Path.GetFullPath("..\Project\Site\ImageFiles")

https://msdn.microsoft.com/de-de/library/system.io.path(v=vs.110).aspx

Tom Henn
  • 125
  • 6