C# .NET - Access to the path “somepath” is denied."

Asked By Rahul Khanna on 24-Nov-13 01:18 AM

When i execute this code in my C# console application, it throws "Access to the path "somepath" is denied(in the below bold highlighted line)."

This is my code.

   static public PdfDocument Open(string PdfPath)
        {
            **using (FileStream fileStream = new FileStream(PdfPath, FileMode.Open, FileAccess.Read))**
            {
                int len = (int)fileStream.Length;
                Byte[] fileArray = new Byte[len];
                fileStream.Read(fileArray, 0, len);
                fileStream.Close();
                return Open(fileArray);
            }
        }

What is going wrong. Any thought? By the way I logged in as system admin and I have full control in the given folder.

Robbe Morris replied to Rahul Khanna on 24-Nov-13 10:58 AM
Try with a different FileAccess or FileShare setting.  It is possible that some other process has a hold of the file and won't let you open it exclusively.